Posts

Python Revision Notes

11. String Operations s = "Python" print (s.upper()) # PYTHON print (s[ 0 : 3 ]) # Pyt print ( "th" in s) # True 12. File Handling f = open ( "data.txt" , "w" ) f.write( "Hello File" ) f.close() f = open ( "data.txt" , "r" ) print (f.read()) f.close() 13. Exception Handling try : a = int ( input ( "Enter number: " )) print ( 10 /a) except ZeroDivisionError: print ( "Division by zero not allowed" ) except ValueError:  print ( "Invalid input" ) 

Python Revision Notes

  9. List & Tuple List : Mutable, ordered lst = [ 1 , 2 , 3 ] lst.append( 4 ) Tuple : Immutable, ordered tup = ( 1 , 2 , 3 ) 10. Dictionary & Set # Dictionary d = { "name" : "Ajm" , "age" : 18 } print (d[ "name" ]) # Set s = { 1 , 2 , 3 , 3 } print (s) # {1,2,3}

Python Revision Notes

  7. Loops for i in range ( 5 ): print (i) while x > 0 : print (x) x -= 1 Break : Exit loop. Continue : Skip iteration. 8. Functions def greet ( name ): return "Hello " + name print (greet( "Ajm" )) Built-in functions: len() , type() , id() , sum() , max() , min() etc.

Python Revision Notes

  5. Operators Arithmetic : + - * / % // ** Comparison : == != > < >= <= Logical : and or not Assignment : = += -= *= etc. Membership : in, not in Identity : is, is not 6. Conditional Statements if x > 0 : print ( "Positive" ) elif x == 0 : print ( "Zero" ) else : print ( "Negative" )

Python Revision Notes

  3. Data Types Numeric : int , float , complex Sequence : list , tuple , range , str Mapping : dict Set types : set , frozenset Boolean : True , False NoneType : None 4. Variables & Input/Output x = 10 # variable y = input ( "Enter: " ) # input (string type by default) z = int (y) # typecasting print ( "Result:" , z + x)

Python Revision Notes

  1. Basics of Python High-level, interpreted, object-oriented, general-purpose language . Easy syntax, dynamically typed (no need to declare variable type). Uses indentation instead of braces {} . 2. Lexical Units Keywords : Reserved words (e.g., if , while , class , True , False ). Identifiers : Names given to variables, functions, etc. Literals : Constant values (e.g., 10 , 3.14 , "hello" , True ). Operators : Symbols for operations ( + , - , * , / , % , == , and , or ). Delimiters : Brackets, colon, comma, etc.