Professional Documents
Culture Documents
Execution
Execution
Execution
====================================================================
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\']