Python Programming Tutorial

Introduction to Python

Python is a high-level, interpreted programming language known for its readability and versatility. It is used in various fields like web development, data analysis, artificial intelligence, and more.

print("Hello, World!")

Python Basics

Learn the basic syntax and structure of Python programming.

# This is a comment
number = 42
print(f"The number is: {number}")

Variables & Data Types

Python supports various data types including integers, floats, strings, and booleans.

age = 25              # Integer
price = 99.99          # Float
grade = 'A'            # String
is_student = True      # Boolean

Control Flow

Control flow statements allow you to control the execution flow of your program.

number = 10

if number > 0:
    print("Positive number")
elif number < 0:
    print("Negative number")
else:
    print("Zero")

# Loop example
for i in range(5):
    print(i)

Functions

Functions are reusable blocks of code that can take inputs and return outputs.

def add(a, b):
    return a + b

result = add(5, 3)  # result = 8

Classes & Objects

Python is an object-oriented programming language that allows you to define classes and create objects.

class Student:
    def __init__(self, name, age):
        self.name = name
        self.age = age
    
    def display(self):
        print(f"Name: {self.name}")
        print(f"Age: {self.age}")

student = Student("John", 21)
student.display()