Python
Python is the most popular high-level language in 2023, mostly used for data science and machine learning.
1. Syntax (Output)
print("welcome")
2. Comments
Single line
#first line comment
Multi line
#multiple line comments
#first line comment
#second line comment
#third line comment
3. Variables
x = 10
y = 10.5
z = "welcome"
print(x, y, z)
4. Arithmetic Operators
x = 9
y = 4
print (x+y)
5. Conditions
x = 15
if x >10:
print("passed")
print("passed")
print("passed")
print("passed")
else:
print("failed")
print("out of if-else")
_______________________________________________
#Conditions/nested if-else(multiple conditions)
x = 100
if x <90:
print("excelent")
elif x < 80:
print("weldone")
elif x < 70:
print("nice")
else:
print("good")
print("out of if-else") #out of else-if
6. loops (while, for)
x = 1
while x < 5:
print("Paksitan")
x = x + 1 #x++
7. functions (code reusability)
def show(x ,y ):
print(x+y)
show(5, 6)
show(3, 4)
show(8, 8)
8. OOP(obj, class, inheritance)
class A:
x = 10
y = 20
def show(self):
print (self.x)
print (self.y)
ob = A() #obj creation
ob.show()
9. Single Inheritance
class A:
def showA(self):
print("parent class A")
obj = A()
obj.showA()
10. Multiple Inheritance
class A:
def showA(self):
print("parent class A")
class B:
def showB(self):
print ("parnt B")
class C(A, B):
def showC(self):
print ("chidl C")
obj = C()
obj.showA()
obj.showB()
obj.showC()
No comments:
Post a Comment