1. Variables
Variables store data.
name = "Arun"
age = 20
height = 5.8
Here:
-
namestores text (string) -
agestores a whole number (integer) -
heightstores a decimal number (float)
print(name)
print(age)
Output:
Arun
20
2. Data Types
Common Python data types:
name = "Python" # string
age = 25 # integer
price = 99.99 # float
is_active = True # boolean
Check a type:
print(type(age))
3. Input and Output
Getting input from the user:
name = input("Enter your name: ")
print("Hello", name)
Example:
Enter your name: Ravi
Hello Ravi
4. Operators
Arithmetic
a = 10
b = 3
print(a + b) # addition
print(a - b) # subtraction
print(a * b) # multiplication
print(a / b) # division
print(a % b) # remainder
Comparison
print(a > b)
print(a < b)
print(a == b)
5. Conditional Statements (if)
Make decisions in code.
age = 18
if age >= 18:
print("Adult")
else:
print("Minor")
Multiple conditions:
marks = 75
if marks >= 90:
print("A")
elif marks >= 70:
print("B")
else:
print("C")
6. Loops
For Loop
for i in range(5):
print(i)
Output:
0
1
2
3
4
While Loop
count = 1
while count <= 5:
print(count)
count += 1
7. Lists
Store multiple values.
fruits = ["apple", "banana", "orange"]
print(fruits[0])
Add an item:
fruits.append("mango")
Loop through a list:
for fruit in fruits:
print(fruit)
8. Functions
Functions let you reuse code.
def greet(name):
print("Hello", name)
greet("Kumar")
Return values:
def add(a, b):
return a + b
result = add(5, 3)
print(result)
9. Dictionariesv
Store data as key-value pairs.
student = {
"name": "Arun",
"age": 20,
"city": "Chennai"
}
print(student["name"])
10. Importing Modules
Use built-in Python libraries.
import math
print(math.sqrt(25))
Output:
5.0
11. Error Handling
Prevent programs from crashing.
try:
num = int(input("Enter number: "))
print(num)
except ValueError:
print("Please enter a valid number")
12. A Complete Beginner Program
name = input("Enter your name: ")
age = int(input("Enter your age: "))
if age >= 18:
print("Hello", name)
print("You are eligible to vote.")
else:
print("Hello", name)
print("You are not eligible to vote.")












