Print function with strings
print("Hello World")
Print function with variables
greeting = "Welcome!"
print(greeting)
Asking user for input
name = input("What is your name? ")
Joining strings together (Concatenation)
print("Dear " + name + ", welcome!")
Rules for variable names
Basic Date Types
Casting
Example
year = int(input("What is your birth year?"))
age = 2022 - year
print("You are now " + str(age) " years old!")
| Math | Python |
|---|---|
| + | + |
| - | - |
| x | * |
| ÷ | / |
| 5⁴ (Exponential) | ** |
| Remainder | % |
| Integer Division | // |
| Math | Python |
|---|---|
| = | == |
| ≠ | != |
| < | < |
| ≤ | <= |
| > | > |
| ≥ | >= |