s P Python is a widely used programming language known for its simplicity It supports multiple programming paradigms including procedural object oriented and functional programming Used in web development data analysis AI automation and more Use type variable to check the data type Variables and Data Types x 10 Integer y 3 14 Floating point name John String is valid True Boolean Operators Arithmetic Comparison Logical and or not Assignment Conditional Statements x 10 if x 5 print Greater than 5 elif x 5 print Equal to 5 else print Less than 5 for i in range 5 0 to 4 print i Loops For Loop While Loop x 0 while x 5 print x P y t h o n L e a r n i n g N o t e y t h o n L e a r n i n g N o t e s 1 I n t r o d u c t i o n t o P y t h o n 2 B a s i c S y n t a x 3 C o n t r o l F l o w x 1 Loop Control break Exit loop continue Skip iteration def greet name return f Hello name print greet John Default parameter values def add a b 10 return a b Lambda function square lambda x x 2 print square 5 Output 25 Lists Mutable numbers 1 2 3 4 numbers append 5 print numbers 0 Access element Tuples Immutable point 3 4 print point 0 Sets Unique elements unique numbers 1 2 3 3 print unique numbers Output 1 2 3 Dictionaries Key Value Pairs person name Alice age 25 print person name Output Alice with open file txt w as f f write Hello world with open file txt r as f print f read try x 10 0 except ZeroDivisionError print Cannot divide by zero finally print Done Classes Objects 4 F u n c t i o n s 5 D a t a S t r u c t u r e s 6 F i l e H a n d l i n g 7 E x c e p t i o n H a n d l i n g 8 O b j e c t O r i e n t e d P r o g r a m m i n g O O P class Person def init self name age self name name self age age def greet self return f Hi I m self name p Person Alice 25 print p greet Output Hi I m Alice Import modules import math print math sqrt 16 Output 4 0 Common Libraries NumPy Numerical computing Pandas Data analysis Matplotlib Data visualization List Comprehensions squares x 2 for x in range 5 Decorators def decorator func def wrapper print Before function call func print After function call return wrapper decorator def say hello print Hello say hello Generators def count up x 0 while x 5 yield x x 1 for num in count up print num 9 M o d u l e s L i b r a r i e s 1 0 A d v a n c e d T o p i c s
View Full Document