Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

5/18/2020 Untitled3

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

NameError: name 'a' is not defined

In [20]: str="Welcome you all"

In [21]: str

Out[21]: 'Welcome you all'

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]

Out[25]: 'Welcome you al'

In [26]: str[:1]

Out[26]: 'W'

In [27]: str[:8]

Out[27]: 'Welcome '

In [28]: str

Out[28]: 'Welcome you all'

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 [33]: str in["hello"]


Out[33]: False

In [34]: max(str)

Out[34]: 'y'

In [36]: str.lower()

Out[36]: 'welcome you all'

str="hello"

In [38]: str

Out[38]: 'Welcome you all'

In [39]: str1="welcome"

In [40]: str1

Out[40]: 'welcome'

In [41]: str+str1

Out[41]: 'Welcome you allwelcome'

In [42]: str1.find("hello")

Out[42]: -1

In [43]: str

Out[43]: 'Welcome you all'

In [44]: str.replace("all",'FDP')

Out[44]: 'Welcome you FDP'

In [45]: str

Out[45]: 'Welcome you all'

In [48]: str.split(' ',2)

Out[48]: ['Welcome', 'you', 'all']

In [49]: list=['physics','chemistry',1997,2000,34.55]

In [50]: list

Out[50]: ['physics', 'chemistry', 1997, 2000, 34.55]

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]

Out[53]: ['physics', 'chemistry', 1997]

In [54]: list[-1]

Out[54]: 34.55

In [55]: list[-2]

Out[55]: 2000

In [56]: list

Out[56]: ['physics', 'chemistry', 1997, 2000, 34.55]

In [58]: list1=['fdp',8687,8.87987,['hello','welcome'],78796]

In [59]: list1

Out[59]: ['fdp', 8687, 8.87987, ['hello', 'welcome'], 78796]

In [61]: list1[0]

Out[61]: 'fdp'

In [62]: list1[1]

Out[62]: 8687

In [63]: list1[3]

Out[63]: ['hello', 'welcome']

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]

Out[67]: [15, 16, 18, [34, 'sdsd', 56], 'welcome']

In [68]: list3[3][3]

Out[68]: [34, 'sdsd', 56]

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]

Out[83]: [34, 'sdsd', 56]

localhost:8888/nbconvert/html/Untitled3.ipynb?download=false 5/11
5/18/2020 Untitled3

In [84]: list3[3][3][2]

Out[84]: 56

In [85]: del list3[3][3][2]

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

Out[91]: [12, 15.934, [15, 16, 18, [34, 'sdsd'], 'welcome']]

In [93]: list3.reverse()

In [94]: list3

Out[94]: [[15, 16, 18, [34, 'sdsd'], 'welcome'], 15.934, 12]

In [95]: tuple=('physics','cn',6786,9898.87687)

In [96]: tuple

Out[96]: ('physics', 'cn', 6786, 9898.87687)

In [97]: tuple[0:]

Out[97]: ('physics', 'cn', 6786, 9898.87687)

In [98]: del tuple

In [99]: tuple

Out[99]: tuple

In [100]: dict={'Name':"FDP",'days':5,'Participation':1200}

In [101]: dict

Out[101]: {'Name': 'FDP', 'days': 5, 'Participation': 1200}

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

Out[106]: {'Name': 'FDP', 'days': 5, 'Participation': 1200, 'college': 'JIT'}

In [107]: dict['college']

Out[107]: 'JIT'

In [108]: len(dict)

Out[108]: 4

In [112]: dict2=dict.copy()

In [113]: dict2

Out[113]: {'Name': 'FDP', 'days': 5, 'Participation': 1200, 'college': 'JIT'}

In [114]: dict2.keys()

Out[114]: dict_keys(['Name', 'days', 'Participation', 'college'])

In [117]: dict2.items()

Out[117]: dict_items([('Name', 'FDP'), ('days', 5), ('Participation', 1200), ('colleg


e', 'JIT')])

In [118]: dict2={'location':'India'}

In [119]: dict2

Out[119]: {'location': 'India'}

In [120]: dict

Out[120]: {'Name': 'FDP', 'days': 5, 'Participation': 1200, 'college': 'JIT'}

In [121]: dict.update(dict2)

localhost:8888/nbconvert/html/Untitled3.ipynb?download=false 7/11
5/18/2020 Untitled3

In [122]: dict

Out[122]: {'Name': 'FDP',


'days': 5,
'Participation': 1200,
'college': 'JIT',
'location': 'India'}

In [123]: dict.values()

Out[123]: dict_values(['FDP', 5, 1200, 'JIT', 'India'])

In [124]: def sample(str):


print(str)
return

In [125]: sample("welcome")

welcome

In [130]: def sample1(mylist):


mylist.append[1,2,3,4,5];
print("values Fun",mylist)
return

In [131]: mylist=[10,20,30]

In [134]: def sample2(name,age=34):


print("Name",name)
print("Age",age)
return

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

In [145]: if (a < b):


print("A is smaller value")
else:
print("B is smaller value")

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

In [152]: for i in range(0,10):


print(i)

0
1
2
3
4
5
6
7
8
9

In [153]: for i in range(10):


print(i)

0
1
2
3
4
5
6
7
8
9

In [154]: for i in range(0,10,2):


print(i)

0
2
4
6
8

localhost:8888/nbconvert/html/Untitled3.ipynb?download=false 10/11
5/18/2020 Untitled3

In [155]: for i in range(0,10,3):


print(i)

0
3
6
9

In [156]: a=2

In [157]: for i in range(0,10,a-1):


print(i)

0
1
2
3
4
5
6
7
8
9

In [158]: for i in range(0,10,a+4-3+1):


print(i)

0
4
8

localhost:8888/nbconvert/html/Untitled3.ipynb?download=false 11/11

You might also like