Python Basics

What you'll learn: Learn Python fundamentals and start your programming journey

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:

  1. Asks for the user’s name
  2. Asks for their age
  3. Calculates birth year
  4. Prints a personalized message

Next Steps

Learn about Python lists, dictionaries, file handling, and object-oriented programming.