Introductory Python
Introductory Python
What is Python?
Comments
'''
This is a
multi-line comment
'''
Variables
name = "Alice"
age = 25
price = 19.99
Data Types
Type Example
int 5
float 5.5
str "Hello"
list [1, 2, 3]
tuple (1, 2, 3)
set {1, 2, 3}
print("Hello", name)
Operators
+ a+b Addition
- a-b Subtraction
* a*b Multiplication
/ a/b Division
// a // b Floor Division
% a%b Modulus
** a ** b Exponentiation
== a == b Equals
!= a != b Not Equal
Conditional Statements
print("Adult")
print("Just 18")
else:
print("Minor")
Loops
For Loop
for i in range(5):
print(i)
While Loop
count = 0
print(count)
count += 1
Functions
def greet():
print("Hello!")
greet()
return a + b
print(add(5, 3))
Example Program
# Simple Calculator
print("Sum is:", a + b)