Skip to main content

Posts

Showing posts from March, 2020

python 3 cheat sheet

1. Variables & Data Types x = 10 # Integer y = 3.14 # Float name = "Alice" # String is_active = True # Boolean fruits = [ "apple" , "banana" , "cherry" ] # List person = { "name" : "John" , "age" : 25 } # Dictionary 2. Basic Operations sum = 5 + 3 # Addition diff = 10 - 4 # Subtraction prod = 6 * 7 # Multiplication quot = 10 / 3 # Division mod = 10 % 3 # Modulus power = 2 ** 3 # Exponentiation 3. Conditional Statements x = 10 if x > 5 : print ( "x is greater than 5" ) elif x == 5 : print ( "x is 5" ) else : print ( "x is less than 5" ) 4. Loops # For Loop for i in range ( 5 ): print (i) # 0, 1, 2, 3, 4 # While Loop x = 5 while x > 0 : print (x) x -= 1 5. Functions def greet ( name ): return f"Hello, {name} !" print (greet( "Alice" )) # Output: Hello, Alice! 6. Lists ...