Execution

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 6

#d1={101:{ 'name': 'Amit', 'Marks': {'M': 65, 'E': 87}},102:{ 'name': 'Mayank',

'Marks': {'M': 72, 'E': 24}}}


d1={}
d1[101]={}
d1[101]['name']='Amit'
d1[101]['Marks']={}
d1[101]['Marks']['M']=65
d1[101]['Marks']['E']=87
d1[102]={}
d1[102]['name']='Mayank'
d1[102]['Marks']={}
d1[102]['Marks']['M']=93
d1[102]['Marks']['E']=63
print('Details',d1)

====================================================================
Python 3.7.6 (tags/v3.7.6:43364a7ae0, Dec 19 2019, 00:42:30) [MSC v.1916 64 bit
(AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> name='Hello World'
>>> name[-4:-12:-1]
'oW olleH'
>>> name='Hello Worldasdsdasdasdsadsdasad'
>>> name[-4:-12:-1]
'adsdasds'
>>> name[-4::-1]
'adsdasdsadsadsdsadlroW olleH'
>>> name='Hello World'
>>> name[:-11:-1]
'dlroW olle'
>>> name[:-12:-1]
'dlroW olleH'
>>> name[::-1]
'dlroW olleH'
>>> num=1901
>>> type(num)
<class 'int'>
>>> name='Ethans'
>>> #ID,name,dept,salary
>>> #ID1,ID2,ID3...ID500
>>> #list vs tuple
>>> l1=[101,'Jatin','IT']
>>> t1=(101,'Jatin','IT')
>>> type(l1)
<class 'list'>
>>> type(t1)
<class 'tuple'>
>>> name='Ethans'
>>> name[-3:]
'ans'
>>> l1[-2:]
['Jatin', 'IT']
>>> t1[::-1]
('IT', 'Jatin', 101)
>>> t1
(101, 'Jatin', 'IT')
>>> t1[-1]
'IT'
>>> t1[0:6:2]
(101, 'IT')
>>> t1
(101, 'Jatin', 'IT')
>>> #What is the difference betweek tuple and list
>>> l1=[101,'Jatin','IT']
>>> t1=(101,'Jatin','IT')
>>> #list is mutable
>>> l1[1]
'Jatin'
>>> l1[1]='Amit'
>>> l1
[101, 'Amit', 'IT']
>>> t1[1]='Amit'
Traceback (most recent call last):
File "<pyshell#34>", line 1, in <module>
t1[1]='Amit'
TypeError: 'tuple' object does not support item assignment
>>> l1
[101, 'Amit', 'IT']
>>> t1
(101, 'Jatin', 'IT')
>>> t1
(101, 'Jatin', 'IT')
>>> name='Ethans'
>>> name='NIIT'
>>> name[0]='S'
Traceback (most recent call last):
File "<pyshell#40>", line 1, in <module>
name[0]='S'
TypeError: 'str' object does not support item assignment
>>> #[]--> indexing/slicing, list
>>> #()--> functions,tuple
>>> l1=[101,'Jatin','IT']
>>> t1=(101,'Jatin','IT')
>>> import sys
>>> sys.getsizeof(t1)
72
>>> sys.getsizeof(l1)
88
>>> #List is bit heavier where as tuple is light
>>> #list is bit heavir and slow
>>> #tuple is lightweight and faster
>>> l1=[101,'Jatin','IT']
>>> t1=(101,'Jatin','IT')
>>> l1=[1,1,2,2,2,22,3,4,5,65,76,87,65]
\
>>> l1
[1, 1, 2, 2, 2, 22, 3, 4, 5, 65, 76, 87, 65]
>>> s1={1,1,2,2,2,22,3,4,5,65,76,87,65}
>>> s1
{1, 2, 3, 4, 5, 65, 76, 22, 87}
>>> #tuple,list,set--> tuple last 2 elements , list reverse , set as it is
>>> l1
[1, 1, 2, 2, 2, 22, 3, 4, 5, 65, 76, 87, 65]
>>> set(l1)
{1, 2, 3, 4, 5, 65, 76, 22, 87}
>>> l1=[101,'Amit','IT','jatin']
>>> d1={'ID':101,'name':'Amit','dept':'IT','Mgr':'Jatin'}
>>> s1={1,1,2,2,2,22,3,4,5,65,76,87,65}
>>> type(s1)
<class 'set'>
>>> s1[0]
Traceback (most recent call last):
File "<pyshell#64>", line 1, in <module>
s1[0]
TypeError: 'set' object is not subscriptable
>>> d1={'ID':101,'name':'Amit','dept':'IT','Mgr':'Jatin'}
>>> s1={1,1,2,2,2,22,3,4,5,65,76,87,65}
>>> type(d1)
<class 'dict'>
>>> d1[0]
Traceback (most recent call last):
File "<pyshell#68>", line 1, in <module>
d1[0]
KeyError: 0
>>> d1['ID']
101
>>> d1
{'ID': 101, 'name': 'Amit', 'dept': 'IT', 'Mgr': 'Jatin'}
>>> d1['name']
'Amit'
>>> d1['Mgr']='Pradeep'
>>> d1
{'ID': 101, 'name': 'Amit', 'dept': 'IT', 'Mgr': 'Pradeep'}
>>> l1
[101, 'Amit', 'IT', 'jatin']
>>> d1={'ID':101,'name':'Amit','dept':'IT','Mgr':'Jatin','name':'Nicky'}
>>> d1
{'ID': 101, 'name': 'Nicky', 'dept': 'IT', 'Mgr': 'Jatin'}
>>> d1={'ID':101,'name':'Amit','dept':'IT','Mgr':'Jatin','name':'Nicky'}
>>> l1=[101,'Amit','IT','Jatin']
>>> l1[4]=90000
Traceback (most recent call last):
File "<pyshell#79>", line 1, in <module>
l1[4]=90000
IndexError: list assignment index out of range
>>> l1.append(90000)
>>> l1
[101, 'Amit', 'IT', 'Jatin', 90000]
>>> d1
{'ID': 101, 'name': 'Nicky', 'dept': 'IT', 'Mgr': 'Jatin'}
>>> d1['name']='Amit'
>>> d1
{'ID': 101, 'name': 'Amit', 'dept': 'IT', 'Mgr': 'Jatin'}
>>> d1['salary']=90000
>>> d1
{'ID': 101, 'name': 'Amit', 'dept': 'IT', 'Mgr': 'Jatin', 'salary': 90000}
>>> l1=[101,'Jatin','IT']
>>> s1={1,1,2,2,2,22,3,4,5,65,76,87,65}
>>> d1={'ID':101,'name':'Amit','dept':'IT','Mgr':'Jatin'}
>>> t1=(101,'Jatin','IT')
>>> d1={'ID':101,'name':'Amit','S1':87,'S2':89}
>>> d1={'ID':101,'name':'Amit','History':87,'Maths':89}
>>> d1
{'ID': 101, 'name': 'Amit', 'History': 87, 'Maths': 89}
>>> d1={'ID':101,'name':'Amit','Makrs':[56,98]}
>>> d1={'ID':101,'name':'Amit','Marks':[56,98]}
>>> d1['Marks']
[56, 98]
>>> d1['Marks'][0]
56
>>> d1['Marks'][1]
98
>>> d1['Marks'][1]=76
>>> d1
{'ID': 101, 'name': 'Amit', 'Marks': [56, 76]}
>>> d1
{'ID': 101, 'name': 'Amit', 'Marks': [56, 76]}
>>> d1['Marks']=(88,67)
>>> d1
{'ID': 101, 'name': 'Amit', 'Marks': (88, 67)}
>>> d1['Marks'][1]=76
Traceback (most recent call last):
File "<pyshell#104>", line 1, in <module>
d1['Marks'][1]=76
TypeError: 'tuple' object does not support item assignment
>>> d1={'ID': 101, 'name': 'Amit', 'Marks':{'M':65,'E':87}}
>>> d1['Marks']['M']
65
>>> d1['Marks']['E']
87
>>> d1['Marks']['E']=59
>>> d1
{'ID': 101, 'name': 'Amit', 'Marks': {'M': 65, 'E': 59}}
>>> l1=[11,22,3,{'ID': 101, 'name': 'Amit', 'Marks':{'M':65,'E':87}},77,88]
>>> len(l1)
6
>>> l1[4]
77
>>> l1[3]
{'ID': 101, 'name': 'Amit', 'Marks': {'M': 65, 'E': 87}}
>>> l1[3]['Marks']
{'M': 65, 'E': 87}
>>> l1[3]['Marks']['E\']

SyntaxError: EOL while scanning string literal


>>> l1[3]['Marks']['E']
87
>>> d1={'ID': 101, 'name': 'Amit', 'Marks': {'M': 65, 'E': 87}}
>>> d2={'ID': 101, 'name': 'Amit', 'Marks': {'M': 65, 'E': 87}}
>>> d1={'ID': [101,102], 'name':['Amit','Mayank'], 'Marks':[ {'M': 65, 'E': 87},
{'M': 46, 'E': 82}]}
>>> d1={'Stud1':{'ID': 101, 'name': 'Amit', 'Marks': {'M': 65, 'E': 87}},'Stud2':
{'ID': 102, 'name': 'Mayank', 'Marks': {'M': 72, 'E': 24}}}
>>> d1['Stud1']
{'ID': 101, 'name': 'Amit', 'Marks': {'M': 65, 'E': 87}}
>>> d1['Stud2']
{'ID': 102, 'name': 'Mayank', 'Marks': {'M': 72, 'E': 24}}
>>> d1={101:{ 'name': 'Amit', 'Marks': {'M': 65, 'E': 87}},102:{ 'name': 'Mayank',
'Marks': {'M': 72, 'E': 24}}}
>>> d1[102]['Marks']['M']
72
>>> d1[101]['Marks']['M']
65
>>> d1[101]['Marks']['E']
87
>>>
= RESTART: C:\Users\Ashwini Girgosavi\AppData\Local\Programs\Python\Python37\
pyprog\hello.py
Details {101: {'name': 'Amit', 'Marks': {'M': 65, 'E': 87}}, 102: {'name':
'Mayank', 'Marks': {'M': 72, 'E': 24}}}
>>>
= RESTART: C:\Users\Ashwini Girgosavi\AppData\Local\Programs\Python\Python37\
pyprog\hello.py
Details {101: {'name': 'Amit', 'Marks': {'M': 65, 'E': 87}}, 102: {'name':
'Mayank', 'Marks': {'M': 72, 'E': 24}}}
72
>>>
= RESTART: C:\Users\Ashwini Girgosavi\AppData\Local\Programs\Python\Python37\
pyprog\hello.py
Traceback (most recent call last):
File "C:\Users\Ashwini Girgosavi\AppData\Local\Programs\Python\Python37\pyprog\
hello.py", line 3, in <module>
d1[101]['name']='Amit'
KeyError: 101
>>>
>>>
>>>
>>> set()
set()
>>> s1=set()
>>> s1
set()
>>>
= RESTART: C:\Users\Ashwini Girgosavi\AppData\Local\Programs\Python\Python37\
pyprog\hello.py
Details {101: {'name': 'Amit', 'Marks': {'M': 65, 'E': 87}}}
Traceback (most recent call last):
File "C:\Users\Ashwini Girgosavi\AppData\Local\Programs\Python\Python37\pyprog\
hello.py", line 9, in <module>
print( d1[102]['Marks']['M'])
KeyError: 102
>>>
= RESTART: C:\Users\Ashwini Girgosavi\AppData\Local\Programs\Python\Python37\
pyprog\hello.py
Details {101: {'name': 'Amit', 'Marks': {'M': 65, 'E': 87}}}
>>>
= RESTART: C:\Users\Ashwini Girgosavi\AppData\Local\Programs\Python\Python37\
pyprog\hello.py
Details {101: {'name': 'Amit', 'Marks': {'M': 65, 'E': 87}}, 102: {'name':
'Mayank', 'Marks': {'M': 93, 'E': 63}}}
>>>
= RESTART: C:\Users\Ashwini Girgosavi\AppData\Local\Programs\Python\Python37\
pyprog\hello.py
Details {101: {'name': 'Amit', 'Marks': {'M': 65, 'E': 87}}, 102: {'name':
'Mayank', 'Marks': {'M': 93, 'E': 63}}}
>>> #TypeCOnversion
>>> t1=(55,66,77,8,9,55,66,77,8)
>>> t1[2]=7888
Traceback (most recent call last):
File "<pyshell#135>", line 1, in <module>
t1[2]=7888
TypeError: 'tuple' object does not support item assignment
>>> list(t1)
[55, 66, 77, 8, 9, 55, 66, 77, 8]
>>> t1
(55, 66, 77, 8, 9, 55, 66, 77, 8)
>>> res=list(t1)
>>> res
[55, 66, 77, 8, 9, 55, 66, 77, 8]
>>> t1
(55, 66, 77, 8, 9, 55, 66, 77, 8)
>>> t1=list(t1)
>>> t1
[55, 66, 77, 8, 9, 55, 66, 77, 8]
>>> t1
[55, 66, 77, 8, 9, 55, 66, 77, 8]
>>> tuple(t1)
(55, 66, 77, 8, 9, 55, 66, 77, 8)
>>> set(t1)
{66, 8, 9, 77, 55}
>>> set(t1)
{66, 8, 9, 77, 55}
>>> list(set(t1)))
SyntaxError: invalid syntax
>>> list(set(t1))
[66, 8, 9, 77, 55]
>>> t1=(556,66,77,889)
>>> t1=list(t1)
>>> t1
[556, 66, 77, 889]
>>> t1[0]=999
>>> t1
[999, 66, 77, 889]
>>> t1=tuple(t1)
>>> int(999.99)
999
>>> float(199)
199.0
>>> str(99999)
'99999'
>>> t1
(999, 66, 77, 889)
>>> dict(t1)
Traceback (most recent call last):
File "<pyshell#159>", line 1, in <module>
dict(t1)
TypeError: cannot convert dictionary update sequence element #0 to a sequence
>>> t1=((33,44),(66,77),(7,8))
>>> dict(t1)
{33: 44, 66: 77, 7: 8}
>>> t1=[(33,44),(66,77),(7,8)]
>>> dict(t1)
{33: 44, 66: 77, 7: 8}
>>>

You might also like