Introduction to Python
Python is a versatile, beginner-friendly programming language used for web development, data science, automation, and more.
Installing Python
Download Python from python.org and install it on your system.
Your First Python Program
print("Hello, World!")
Variables and Data Types
# String
name = "Alice"
# Integer
age = 25
# Float
height = 5.6
# Boolean
is_student = True
# List
colors = ["red", "green", "blue"]
# Dictionary
person = {
"name": "Alice",
"age": 25
}
Basic Operations
# Arithmetic
result = 10 + 5
difference = 10 - 5
product = 10 * 5
quotient = 10 / 5
# String concatenation
greeting = "Hello, " + name
# String formatting
message = f"My name is {name} and I am {age} years old"
Control Flow
If Statements
if age >= 18:
print("You are an adult")
elif age >= 13:
print("You are a teenager")
else:
print("You are a child")
Loops
# For loop
for color in colors:
print(color)
# While loop
count = 0
while count < 5:
print(count)
count += 1
Functions
def greet(name):
return f"Hello, {name}!"
# Call the function
message = greet("World")
print(message)
Practice Exercise
Create a program that:
- Asks for the user’s name
- Asks for their age
- Calculates birth year
- Prints a personalized message
Next Steps
Learn about Python lists, dictionaries, file handling, and object-oriented programming.