Python Programming — Beginner Study Material
1. Introduction to Python
Python is a high-level, interpreted, and general-purpose programming language. It emphasizes
readability and simplicity, making it ideal for beginners and professionals alike.
2. Features of Python
• Easy to learn and use
• Interpreted and dynamically typed
• Object-oriented
• Extensive standard libraries
• Portable and cross-platform
• Supports GUI and web development
3. Python Syntax and Indentation
Python uses indentation (spaces or tabs) to define blocks of code instead of braces {}.
Example:
if 5 > 2:
print('Five is greater than two!')
4. Variables and Data Types
Variables store data values and are created when first assigned.
Example:
x = 10
name = 'Alice'
pi = 3.14
Common data types: int, float, str, bool, list, tuple, dict, set.
5. Operators
• Arithmetic: +, -, *, /, %, **, //
• Comparison: ==, !=, >, <, >=, <=
• Logical: and, or, not
• Assignment: =, +=, -=, etc.
6. Conditional Statements
Used to perform different actions based on conditions.
Example:
age = 18
if age >= 18:
print('Adult')
else:
print('Minor')
7. Loops
• For Loop:
for i in range(5):
print(i)
• While Loop:
count = 0
while count < 5:
print(count)
count += 1
8. Functions
Functions are reusable blocks of code defined using the def keyword.
Example:
def greet(name):
print('Hello,', name)
greet('Shubham')
9. Lists and Tuples
• List: A mutable sequence of items.
fruits = ['apple', 'banana', 'cherry']
• Tuple: An immutable sequence.
colors = ('red', 'green', 'blue')
10. Dictionaries and Sets
• Dictionary: Key-value pairs.
student = {'name': 'John', 'age': 20}
• Set: Unordered collection of unique items.
nums = {1, 2, 3, 4}
11. Input and Output
name = input('Enter your name: ')
print('Hello', name)
12. File Handling
• Writing to a file:
with open('data.txt', 'w') as f:
f.write('Hello Python!')
• Reading a file:
with open('data.txt', 'r') as f:
print(f.read())
13. Exception Handling
Used to handle runtime errors gracefully.
try:
print(10/0)
except ZeroDivisionError:
print('Cannot divide by zero!')
14. Conclusion
Python is one of the most versatile programming languages today. Practice regularly to strengthen
your understanding and explore advanced topics like OOP, modules, and libraries such as NumPy
and Pandas.
Practice Section
Try writing small Python programs daily to master the syntax and logic.