Class 3
Class 3
December 9, 2024
[ ]:
Basics of Python
[ ]: print ('welcome to python basics')
[ ]: first_name = "praveen"
age = 36
marital_status = True
height = 5.5
laast_name = "kumar"
[ ]: print(first_name)
print(age)
print(marital_status)
print(height)
print(laast_name)
praveen
36
True
5.5
kumar
[ ]: type(first_name),type(age),type(marital_status),type(height),type(laast_name)
[ ]: type(laast_name)
[ ]: str
1
[ ]: laast_name.capitalize()
[ ]: 'Kumar'
[ ]: first_name.capitalize()
[ ]: 'Praveen'
[ ]: pi = 3.14
[ ]: type(pi)
[ ]: float
[ ]: pi.is_integer()
[ ]: False
[ ]: name.split(sep="i")
[ ]: name1.split(sep="a")
[ ]: name.split()
[ ]: name1.split()
[ ]: name.find("i")
[ ]: 2
[ ]: name.find("i",name.find("i")+1)
[ ]: 11
[ ]: name1.find("a")
2
[ ]: 2
[ ]: name1.find("a",name1.find("a")+1)
[ ]: 11
[ ]: 10
10
20
[ ]: b=30
print(b)
b=40
print(b)
b=50
print(b)
30
40
50
[ ]: print(b)
50
[ ]: _name="python"
print(_name)
python
[ ]: Password="abc@123"
Password
[ ]: 'abc@123'
3
[ ]: _last_name="pqr"
_last_name
[ ]: 'pqr'
[ ]: a_23="xyz"
a_23
[ ]: 'xyz'
30
[ ]: """
This is a multi-line comment.
We are making this comment.
"""
[ ]: '''
This is a multi-line comment
extending to multiple lines
'''
[ ]: '''
comment
'''
[ ]: '\ncomment\n'
[ ]: """
this
is
multi-line
comment
"""
[ ]: '\nthis\nis\nmulti-line\ncomment\n'
4
[ ]: '''
one
more
multi-line
comment
with
single-quotes
'''
[ ]: '\none\nmore\nmulti-line\ncomment\nwith\nsingle-quotes\n'
[ ]: a=21
b=10
#addition
c=a+b
#subtraction
d=a-b
#multiplication
e=a*b
#division
f=a/b
#modulus
g=a%b
#Quotient
h=a//b
[ ]: print("Addition is:",c)
print("Subtraction is",d)
print("Multiplication is",e)
print("Divisiob is",f)
print("Remainder is",g)
print("Quotient is",h)
Addition is: 31
Subtraction is 11
Multiplication is 210
Divisiob is 2.1
Remainder is 1
Quotient is 2
[ ]: m=3
n=2
print(m**n)
print(n**m)
5
8
Comparision Operators
[15]: a=20
b=10
[16]: a==b
[16]: False
[17]: a>b
[17]: True
[18]: a<b
[18]: False
[19]: a>=b
[19]: True
[20]: a<=b
[20]: False
[21]: a!=b
[21]: True
Logical Operators And operator - if either of the conditions is false, it returns false: and True
and True returns True
True and False returns False
False and True returns False
False and False returns False
Or Operator - if either of the conditions are true, it returns a true: or True or True returns True
True or False returns True
False or False returns False
False or True returns True
Not operator - it will invert the boolean input: not not True returns False ! False returns True
[22]: True and True
6
[22]: True
[23]: True
[24]: False
[27]: False
[28]: True
[29]: (a,b)
[30]: True
[31]: False
[32]: False
[33]: True
[35]: False
[37]: True
7
[38]: a=200
type(a)
[38]: int
[40]: b=3.234
type(b)
[40]: float
[41]: a=str(a)
a
[41]: '200'
[42]: a=float(a)
a
[42]: 200.0
[43]: b=int(b)
b
[43]: 3
[44]: b=str(b)
b
[44]: '3'
[45]: bool(a)
[45]: True
[46]: bool(b)
[46]: True
[49]: c=0
bool(c)
[49]: False
[50]: bool(20)
[50]: True
8
[51]: bool(-100)
[51]: True
[52]: bool(0)
[52]: False
input method
[53]: savings=input("How much You Saved?")
[54]: savings
[54]: '20000'
[56]: savings=int(savings)
savings
[56]: 20000
[64]: Weight
[64]: '72.56'
[65]: Weight=float(Weight)
Weight
[65]: 72.56
[68]: # if the base of right angle traingle is 10 cm and hight of triangle is 20 cm.␣
↪find the hypoteneous of the triangle
9
# ans is square root of hight**2 + base**2
import math
base, height = 10, 20
hypotenuse = math.sqrt((base ** 2) + (height ** 2))
print("Hypotenuse = ", hypotenuse)
Hypotenuse = 22.360679774997898
10