Python NOTES
1. Varaibles , type check, combine, int datatype string literals str(age)// number convert into
string, float, boolean
2. Multiple assignment
2.Multiple assigment assign muliple line of code in single line
name, age, human = 'danny', 22, True
print(name)
print(age)
print(human)
danny = raga = niyaz = 22
print(danny)
print(raga)
print(niyaz)
3. String methods
4. Type casting
#typecast
name = "danny"
age= 22
time = 12.40
age = str(age)
time = int(time)
print(age*3)
print(time)
5. Use input
name = input("enter your name: ")
age = int(input("enter your age: "))
print("hi "+name)
print("your age is "+str(age)+" your adult go to job")
6. Slicing
2 types indexing & slicing
name = "dhaniyavel"
slice_name = name[::1]
print(slice_name)
in case you leave empty in star stop it casually take start-0 stop-last or end ::1
SYNTAX NAME[START:STOP:STEP]
website = "http://google.com"
slicing (step,reverese)//eg(4,-3)
slice = slice(7,-4)
print(website[slice])
7. If elif else statement
8. Logical operator and or note one or more conditon
9. While loop is unlimited
10. For loop is limited
For I in range(start, end)
for I in range(start,end,step)
11. To check the range conditon
while True:
a = int(input("enter the number between 1-3: "))
if 1 <= a <= 3:
print("It is in the range")
else:
print("it is out of range")
12. List & Tuples danny=[] //list danny=() //tuples
13. Read a text file
14. Write file file = open(‘filename’, ‘r’) //2nd argument r means read w means write
15. Find & count method
variable = ‘name’
varaiable.find(‘e’) or count(‘a’)
Class & object
class details:
def __init__(self,name,age):
self.name = name
self.age = age
log = details('Dhaniyavel',22)
print(log.name)
16. Del, pass two methods del is used to delete pass used to simply pass
Inheritance
from new import student
class home(student):
pass
don = home
print(don.name, don.age, don.gender)
17. Inheritance syntax is class name(here inherit class name):