Python Practice Day 2
Python Practice Day 2
Python Practice Day 2
February 1, 2022
[1]: a=1
b=3
a==b
[1]: False
[2]: a=1
b=3
a>=b
[2]: False
[3]: a=1
b=3
a<=b
[3]: True
[4]: a+b!=a-b
[4]: True
[5]: a=32
b=34
c=2
a+c==b
[5]: True
[6]: print(0 or 1)
[7]: "roger"
[7]: 'roger'
[8]: 'Roger'
1
[8]: 'Roger'
[15]: print("""My
name
is Roger
""")
My
name
is Roger
[17]: fam[2]="Ram"
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-17-e5dfb891d05b> in <module>
----> 1 fam[2]="Ram"
2
mazenet_ey = [1,3,4,5,6,3.5,6.7,8.6,7.1,True,False,"hello","you","are␣
,→well","done","NOT","OR","AND"]
[32]: itemcopy=mazenet_ey[:]
print(mazenet_ey)
print(itemcopy)
[1, 3, 4, 5, 6, 3.5, 6.7, 8.6, 7.1, True, False, 'hello', 'you', 'are well',
'done', 'NOT', 'OR', 'AND']
[1, 3, 4, 5, 6, 3.5, 6.7, 8.6, 7.1, True, False, 'hello', 'you', 'are well',
'done', 'NOT', 'OR', 'AND']
[38]: print(mazenet_ey)
mazenet_ey=mazenet_ey + ["suresh"]
print(mazenet_ey)
[39]: mazenet_ey[6::2]
[43]: print(sorted(mazenet_ey,key=len))
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-43-d11ae424d080> in <module>
----> 1 print(sorted(mazenet_ey,key=len))
[46]: _abc = 78
print(_abc)
78
3
File "<ipython-input-2-adf02841968c>", line 1
123 = 23
^
SyntaxError: cannot assign to literal
[5]: if = 35
or = "Roger" #using keyword as variable name
[6]: 'Mazenet'
[7]: 5
[8]: 1*4*77
3+99+23
[8]: 125
4
[9]: 444%4
55+5
[9]: 60
[11]: """This
is
multiline"""
[12]: type(56)
[12]: int
[18]: a=5
b=3
c=a+b
print(c)#random indentation
5
[17]: a=5
b=3
c=a+b
print(c)
[19]: name="Mazenet"
isinstance(name,str)
[19]: True
[20]: name=34
isinstance(name,int)
[20]: True
[21]: name="Mazenet"
isinstance(name,int)
[21]: False
[22]: name=77.9
isinstance(name,float)
[22]: True
[23]: print(type(True))
<class 'bool'>
[24]: 1 + 1 #
[24]: 2
[25]: 2 - 1 #1
[25]: 1
[26]: 2 * 2 #4
[26]: 4
[27]: 4 / 2 #2
6
[27]: 2.0
[28]: 4 % 3 #1
[28]: 1
[29]: 4 ** 2 #16
[29]: 16
[30]: 4 // 2 #2
[30]: 2
[31]: 2**44
[31]: 17592186044416
[34]: a=1
b=3
a==b
[34]: False
[35]: a=1
b=3
a>=b
[35]: False
[36]: a=1
b=3
a<=b
[36]: True
[37]: a+b!=a-b
[37]: True
7
[38]: a=32
b=34
c=2
a+c==b
[38]: True
not condition1
[39]: False
[40]: True
[41]: False
8
[46]: False
[49]: True
[50]: False
[51]: False
[52]: True
[55]: name="55.9"
name.isdecimal()
[55]: False
[56]: name="abc"
name.upper()
[56]: 'ABC'
[57]: name="ABC"
name.lower()
[57]: 'abc'
[58]: name="apoorv"
name.title()
[58]: 'Apoorv'
0.0.2 tuple
9
(1, 2, 3, 4, 5, 6)
(1, 2, 3, 4, 5, 6)
None
[19]: t1=(1,2,3,["apple","mangoes"])
print(t1)
[20]: t2=(1,2,3,4,{"name":"Roger","age":32.4})
print (t2)
[22]: dic1={1:"44",(1,2,3):45,"Name":True}
print(dic1)
[25]: print(list(dic1))
print(dic1)
dic1.get(1)
[25]: '44'
10
[29]: print(t1)
t1=list(t1)
t1[2]=45
t1=tuple(t1)
print(t1)
[30]: t1[2:]
[32]: t1[-1:-3:-1]
[33]: t1[::-1]
[36]: y=("apples","mangoes",'watermelon')
z=("cherry",)
y+=z
print(y)
[37]: y=( , )
[40]: y=("",)
print(y)
('',)
[47]: y=["apples","mangoes",'watermelon']
z=("cherry",)
y.sort()
print(y)
print(sorted(y,reverse=True))
11
['apples', 'mangoes', 'watermelon']
['watermelon', 'mangoes', 'apples']
[52]: y=("apples","mangoes",'watermelon',"aaa","zzz","pikaboo")
print(tuple(reversed(y)))
print(y[::-1])
[45]: y=([1,2,3,4],)
print(type(y))
<class 'tuple'>
[53]: t1=(1,2,3,4)
t2=("apples","Mangoes","Cherry")
t3=(True,False)
t2+t1+t3
[55]: t2=list(t2)
t2[2]="suresh"
t2=tuple(t2)
print(t2)
[60]: t1=(4,5,67,8,9,4,5,5,5,"apple",'apple',4)
t2=({2:"raji",True:55},)
t1+t2
[65]: t1.index(5)
[65]: 1
[66]: t1[0]
[66]: 4
[67]: t1[3]
[67]: 8
[68]: t1[2]
12
[68]: 67
[69]: t1[9]
[69]: 'apple'
[70]: t1[11]
[70]: 4
[71]: t1[5]
[71]: 4
[72]: t1[-6]
[72]: 5
[73]: t1[-4]
[73]: 5
[74]: t1[-3]
[74]: 'apple'
[75]: t1[-0]
[75]: 4
[ ]: t1[0]
13