Professional Documents
Culture Documents
Hands - Python
Hands - Python
In [4]: a=10
In [5]: a
Out[5]: 10
In [6]: b=78.986
In [7]: b
Out[7]: 78.986
In [8]: c="hello"
In [9]: print(a)
10
In [10]: a=b=c=1
In [11]: a
Out[11]: 1
In [12]: b
Out[12]: 1
In [13]: c
Out[13]: 1
In [14]: a,b,c=1,67.98,"Hello"
In [15]: a
Out[15]: 1
In [16]: b
Out[16]: 67.98
In [17]: c
Out[17]: 'Hello'
In [18]: del a
localhost:8888/nbconvert/html/Untitled3.ipynb?download=false 1/11
5/18/2020 Untitled3
In [19]: a
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-19-3f786850e387> in <module>()
----> 1 a
In [21]: str
In [22]: str[0]
Out[22]: 'W'
In [23]: str[1]
Out[23]: 'e'
In [24]: str[0:6]
Out[24]: 'Welcom'
In [25]: str[0:-1]
In [26]: str[:1]
Out[26]: 'W'
In [27]: str[:8]
In [28]: str
In [30]: str*4
Out[30]: 'Welcome you allWelcome you allWelcome you allWelcome you all'
In [31]: len(str)
Out[31]: 15
In [32]: str[2:len(str)-8]
Out[32]: 'lcome'
localhost:8888/nbconvert/html/Untitled3.ipynb?download=false 2/11
5/18/2020 Untitled3
In [34]: max(str)
Out[34]: 'y'
In [36]: str.lower()
str="hello"
In [38]: str
In [39]: str1="welcome"
In [40]: str1
Out[40]: 'welcome'
In [41]: str+str1
In [42]: str1.find("hello")
Out[42]: -1
In [43]: str
In [44]: str.replace("all",'FDP')
In [45]: str
In [49]: list=['physics','chemistry',1997,2000,34.55]
In [50]: list
localhost:8888/nbconvert/html/Untitled3.ipynb?download=false 3/11
5/18/2020 Untitled3
In [51]: list[0]
Out[51]: 'physics'
In [52]: list[1]
Out[52]: 'chemistry'
In [53]: list[0:3]
In [54]: list[-1]
Out[54]: 34.55
In [55]: list[-2]
Out[55]: 2000
In [56]: list
In [58]: list1=['fdp',8687,8.87987,['hello','welcome'],78796]
In [59]: list1
In [61]: list1[0]
Out[61]: 'fdp'
In [62]: list1[1]
Out[62]: 8687
In [63]: list1[3]
In [64]: list1[3][0]
Out[64]: 'hello'
In [65]: list3=[12,15.934,'hello',[15,16,18,[34,'sdsd',56],'welcome']]
In [66]: list3
Out[66]: [12, 15.934, 'hello', [15, 16, 18, [34, 'sdsd', 56], 'welcome']]
localhost:8888/nbconvert/html/Untitled3.ipynb?download=false 4/11
5/18/2020 Untitled3
In [67]: list3[3]
In [68]: list3[3][3]
In [69]: list3[3][3][1]
Out[69]: 'sdsd'
In [72]: list3[3][3][1][1:3]
Out[72]: 'ds'
In [73]: list3
Out[73]: [12, 15.934, 'hello', [15, 16, 18, [34, 'sdsd', 56], 'welcome']]
In [74]: list3[2]
Out[74]: 'hello'
In [75]: list3[2]="dello"
In [76]: list3
Out[76]: [12, 15.934, 'dello', [15, 16, 18, [34, 'sdsd', 56], 'welcome']]
In [77]: list3
Out[77]: [12, 15.934, 'dello', [15, 16, 18, [34, 'sdsd', 56], 'welcome']]
In [78]: list3.pop(2)
Out[78]: 'dello'
In [79]: list3
Out[79]: [12, 15.934, [15, 16, 18, [34, 'sdsd', 56], 'welcome']]
In [80]: list3.insert(1,"dello")
In [81]: list3
Out[81]: [12, 'dello', 15.934, [15, 16, 18, [34, 'sdsd', 56], 'welcome']]
In [83]: list3[3][3]
localhost:8888/nbconvert/html/Untitled3.ipynb?download=false 5/11
5/18/2020 Untitled3
In [84]: list3[3][3][2]
Out[84]: 56
In [86]: list3
Out[86]: [12, 'dello', 15.934, [15, 16, 18, [34, 'sdsd'], 'welcome']]
In [87]: len(list3)
Out[87]: 4
In [88]: list3.count(12)
Out[88]: 1
In [90]: list3.remove('dello')
In [91]: list3
In [93]: list3.reverse()
In [94]: list3
In [95]: tuple=('physics','cn',6786,9898.87687)
In [96]: tuple
In [97]: tuple[0:]
In [99]: tuple
Out[99]: tuple
In [100]: dict={'Name':"FDP",'days':5,'Participation':1200}
In [101]: dict
localhost:8888/nbconvert/html/Untitled3.ipynb?download=false 6/11
5/18/2020 Untitled3
In [102]: dict['Name']
Out[102]: 'FDP'
In [103]: type('Name')
Out[103]: str
In [105]: dict['college']='JIT'
In [106]: dict
In [107]: dict['college']
Out[107]: 'JIT'
In [108]: len(dict)
Out[108]: 4
In [112]: dict2=dict.copy()
In [113]: dict2
In [114]: dict2.keys()
In [117]: dict2.items()
In [118]: dict2={'location':'India'}
In [119]: dict2
In [120]: dict
In [121]: dict.update(dict2)
localhost:8888/nbconvert/html/Untitled3.ipynb?download=false 7/11
5/18/2020 Untitled3
In [122]: dict
In [123]: dict.values()
In [125]: sample("welcome")
welcome
In [131]: mylist=[10,20,30]
In [135]: sample2(age=50,name="hello")
Name hello
Age 50
In [136]: a=10
In [137]: b=20
In [138]: c=30
In [139]: a+b
Out[139]: 30
In [140]: a+b-c+a
Out[140]: 10
localhost:8888/nbconvert/html/Untitled3.ipynb?download=false 8/11
5/18/2020 Untitled3
In [141]: a+b-c+a+b-c/2
Out[141]: 15.0
In [142]: a>b
Out[142]: False
In [143]: a<b
Out[143]: True
In [144]: a*b
Out[144]: 200
A is smaller value
In [146]: a=0
In [150]: a=0
while(a>5):
print("hello")
a=a+1
In [149]: count=0
while(count<9):
print("count is",count)
count=count+1
print("Thank you")
count is 0
Thank you
count is 1
Thank you
count is 2
Thank you
count is 3
Thank you
count is 4
Thank you
count is 5
Thank you
count is 6
Thank you
count is 7
Thank you
count is 8
Thank you
localhost:8888/nbconvert/html/Untitled3.ipynb?download=false 9/11
5/18/2020 Untitled3
In [151]: count=0
while(count<9):
print("count is",count)
count=count+1
print("Thank you")
count is 0
count is 1
count is 2
count is 3
count is 4
count is 5
count is 6
count is 7
count is 8
Thank you
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
2
4
6
8
localhost:8888/nbconvert/html/Untitled3.ipynb?download=false 10/11
5/18/2020 Untitled3
0
3
6
9
In [156]: a=2
0
1
2
3
4
5
6
7
8
9
0
4
8
localhost:8888/nbconvert/html/Untitled3.ipynb?download=false 11/11