Python Programming for Beginners
A concise reference guide for developers and students.
Published 2025 | Open Knowledge Series
What is Python?
Python is a high-level, interpreted programming language known for its clear syntax and
readability. Created by Guido van Rossum in 1991, it has become one of the most popular
languages for web development, data science, automation, and more.
Variables and Data Types
Python supports several built-in data types:
name = 'Alice' # string
age = 30 # integer
height = 5.9 # float
active = True # boolean
items = [1, 2, 3] # list
info = {'key': 'val'}# dict
Control Flow
Control program execution with conditionals and loops:
if x > 0:
print('positive')
elif x < 0:
print('negative')
else:
print('zero')
for i in range(10):
print(i)
while condition:
do_something()
Functions
Functions encapsulate reusable code blocks:
def greet(name, greeting='Hello'):
return f'{greeting}, {name}!'
result = greet('Alice')
print(result) # Hello, Alice!
Lists and Dictionaries
Lists store ordered collections. Dictionaries store key-value pairs.
fruits = ['apple', 'banana', 'cherry']
[Link]('date')
[Link]()
person = {'name': 'Bob', 'age': 25}
person['email'] = 'bob@[Link]'
print([Link]('name'))
Error Handling
Handle errors gracefully with try/except blocks:
try:
result = 10 / 0
except ZeroDivisionError as e:
print(f'Error: {e}')
finally:
print('Always runs')