Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
121 views

Python Day1 1

The document shows the output of commands run in a Python interpreter shell. It explores basic Python data types like lists and dictionaries, performing common operations like sorting, joining, and iterating over elements. Various errors are also demonstrated.

Uploaded by

sachin1504
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
121 views

Python Day1 1

The document shows the output of commands run in a Python interpreter shell. It explores basic Python data types like lists and dictionaries, performing common operations like sorting, joining, and iterating over elements. Various errors are also demonstrated.

Uploaded by

sachin1504
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

Microsoft Windows [Version 6.2.

9200]
(c) 2012 Microsoft Corporation. All rights reserved.
C:\Users\seema>cd ..
C:\Users>cd ..\
C:\>cd Python27
C:\Python27>dir
Volume in drive C is Windows
Volume Serial Number is A806-62A4
Directory of C:\Python27
07-02-2014
07-02-2014
07-02-2014
07-02-2014
07-02-2014
08-02-2014
07-02-2014
10-11-2013
10-11-2013
10-11-2013
10-11-2013
27-10-2013
07-02-2014
07-02-2014
07-02-2014
10-11-2013

23:34
<DIR>
.
23:34
<DIR>
..
23:31
<DIR>
DLLs
23:31
<DIR>
Doc
23:31
<DIR>
include
02:12
<DIR>
Lib
23:31
<DIR>
libs
19:28
38,573 LICENSE.txt
11:14
375,685 NEWS.txt
19:24
26,624 python.exe
19:24
27,136 pythonw.exe
17:00
55,208 README.txt
23:34
<DIR>
Scripts
23:31
<DIR>
tcl
23:31
<DIR>
Tools
19:23
49,664 w9xpopen.exe
6 File(s)
572,890 bytes
10 Dir(s) 437,429,100,544 bytes free

C:\Python27>python.exe
Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>

>>> cls
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'cls' is not defined
>>> clear
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'clear' is not defined
>>> cls
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'cls' is not defined
>>> a=[cccc,dddd,ffff,gggffe,hhh,jjj,ttt,bttt,aaaaaaaaaaaaaazzz]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'cccc' is not defined
>>> a = [cccc,dddd,ffff,gggffe,hhh,jjj,ttt,bttt,aaaaaaaaaaaaaazzz]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'cccc' is not defined
>>> a = ['cccc','dddd','ffff','gggffe','hhh','jjj','ttt','bttt','aaaaaaaaaaaaaaz
zz']
>>>
>>>
>>> sorted(a)
['aaaaaaaaaaaaaazzz', 'bttt', 'cccc', 'dddd', 'ffff', 'gggffe', 'hhh', 'jjj', 't
tt']
>>> a = ['cccc','dddd','ffff','gggffe','hhh','jjj','ttt','bttt','aaaaaaaaaaaaaaz
zz','aaaabbbbbcc','acbbb']
>>> sorted(a)
['aaaaaaaaaaaaaazzz', 'aaaabbbbbcc', 'acbbb', 'bttt', 'cccc', 'dddd', 'ffff', 'g
ggffe', 'hhh', 'jjj', 'ttt']
>>> sorted(a, key=len)
['hhh', 'jjj', 'ttt', 'cccc', 'dddd', 'ffff', 'bttt', 'acbbb', 'gggffe', 'aaaabb
bbbcc', 'aaaaaaaaaaaaaazzz']
>>>
>>>
>>>
>>>
>>>
>>> sorted(a, key=len)
['hhh', 'jjj', 'ttt', 'cccc', 'dddd', 'ffff', 'bttt', 'acbbb', 'gggffe', 'aaaabb
bbbcc', 'aaaaaaaaaaaaaazzz']
>>> '-'.join(a)
'cccc-dddd-ffff-gggffe-hhh-jjj-ttt-bttt-aaaaaaaaaaaaaazzz-aaaabbbbbcc-acbbb'
>>> b='-'.join(a)
>>> b
'cccc-dddd-ffff-gggffe-hhh-jjj-ttt-bttt-aaaaaaaaaaaaaazzz-aaaabbbbbcc-acbbb'
>>> b,split('-')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'split' is not defined
>>> b.split('-')
['cccc', 'dddd', 'ffff', 'gggffe', 'hhh', 'jjj', 'ttt', 'bttt', 'aaaaaaaaaaaaaaz
zz', 'aaaabbbbbcc', 'acbbb']
>>> result=[]
>>> for s in a:
... result.append(s)
...
>>> result

['cccc', 'dddd', 'ffff', 'gggffe', 'hhh', 'jjj', 'ttt', 'bttt', 'aaaaaaaaaaaaaaz


zz', 'aaaabbbbbcc', 'acbbb']
>>> a
['cccc', 'dddd', 'ffff', 'gggffe', 'hhh', 'jjj', 'ttt', 'bttt', 'aaaaaaaaaaaaaaz
zz', 'aaaabbbbbcc', 'acbbb']
>>> range(20)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
>>> (x,y)=(1,2)
>>> x
1
>>> y
2
>>> (x,y)=(y,x)
>>> x
2
>>> y
1
>>> d={}
>>> d
{}
>>> d={ }
>>> d
{}
>>> d['a']=alpha
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'alpha' is not defined
>>> d['a']='alpha'
>>> d['b']='beta'
>>> d['g']='gamma'
>>> d['o']='omega'
>>> a
['cccc', 'dddd', 'ffff', 'gggffe', 'hhh', 'jjj', 'ttt', 'bttt', 'aaaaaaaaaaaaaaz
zz', 'aaaabbbbbcc', 'acbbb']
>>> d
{'a': 'alpha', 'b': 'beta', 'o': 'omega', 'g': 'gamma'}
>>> d['o']
'omega'
>>> d['a']
'alpha'
>>> d['bb']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: 'bb'
>>> d.get('x')
>>> s
'acbbb'
>>> d
{'a': 'alpha', 'b': 'beta', 'o': 'omega', 'g': 'gamma'}
>>> d.get('a')
'alpha'
>>> a in d
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'list'
>>> 'a' in d
True
>>> 'al' in d
False
>>> 'alpha' in d

False
>>> d.keys()
['a', 'b', 'o', 'g']
>>> d
{'a': 'alpha', 'b': 'beta', 'o': 'omega', 'g': 'gamma'}
>>> d.values()
['alpha', 'beta', 'omega', 'gamma']
>>> for a in sorted(d.keys()):
... print 'key:' , a , '->', d[k]
...
key: a ->
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
NameError: name 'k' is not defined
>>> for a in sorted(d.keys()):
... print 'key:' , a , '->', d[a]
...
key: a -> alpha
key: b -> beta
key: g -> gamma
key: o -> omega
>>> for tuple in d.items"
File "<stdin>", line 1
for tuple in d.items"
^
SyntaxError: EOL while scanning string literal
>>> for tuple in d.items
File "<stdin>", line 1
for tuple in d.items
^
SyntaxError: invalid syntax
>>> for tuple in d.items:
... print tuple
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'builtin_function_or_method' object is not iterable
>>> d.items()
[('a', 'alpha'), ('b', 'beta'), ('o', 'omega'), ('g', 'gamma')]
>>> d
{'a': 'alpha', 'b': 'beta', 'o': 'omega', 'g': 'gamma'}
>>>
>>> for tuple in d.items():
... print tuple
...
('a', 'alpha')
('b', 'beta')
('o', 'omega')
('g', 'gamma')
>>> for tuple in d.items:
... print tuple
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'builtin_function_or_method' object is not iterable
>>> d
{'a': 'alpha', 'b': 'beta', 'o': 'omega', 'g': 'gamma'}
>>> d.items()
[('a', 'alpha'), ('b', 'beta'), ('o', 'omega'), ('g', 'gamma')]
>>> d

{'a': 'alpha', 'b': 'beta', 'o': 'omega', 'g': 'gamma'}


>>> d[0]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: 0
>>> d(0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'dict' object is not callable
>>> d.keys(0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: keys() takes no arguments (1 given)
>>> d.keys()
['a', 'b', 'o', 'g']
>>> d.items()
[('a', 'alpha'), ('b', 'beta'), ('o', 'omega'), ('g', 'gamma')]
>>> d.items(1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: items() takes no arguments (1 given)
>>> d.items(a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: items() takes no arguments (1 given)
>>> d(a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'dict' object is not callable
>>> d(0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'dict' object is not callable
>>> d[0]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: 0
>>> d[a]
'omega'
>>> a = [1,2,3,4,5]
>>> a[::2]
[1, 3, 5]
>>>

You might also like