Python_Learning_Guide
Python_Learning_Guide
designed for beginners. Each chapter covers fundamental topics with examples and exercises.
1. Introduction to Python
Python is a popular programming language known for its simplicity and versatility.
Key features:
- Easy to learn
- Open source
Examples:
print("Hello, World!")
a=5
b = 10
print(a + b)
2. Variables and Data Types
Variables are used to store data. Python supports different data types:
Examples:
name = "Alice"
age = 25
height = 5.6
is_student = True
Python uses the input() function to get user input and print() to display output.
Examples:
Examples:
a = 10
b=3
print(a + b, a - b, a * b, a / b, a % b)
Comparison:
print(a > b, a == b, a != b)
Logical:
Examples:
else:
Examples:
for i in range(5):
print(i)
n=5
while n > 0:
print(n)
n -= 1
7. Functions
Examples:
def greet(name):
greet("Alice")
8. Lists and Tuples
Examples:
print(fruits[0])
numbers = (1, 2, 3)
print(numbers[1])
9. Dictionaries
Examples:
print(person["name"], person.get("age"))
10. Exception Handling
Examples:
try:
print(x / 0)
except ValueError:
print("Invalid input!")
except ZeroDivisionError: