Mastering Python: Beginner to Intermediate
1. Introduction to Python
Python is a versatile, high-level programming language that's great for beginners. It's used in web
development, data analysis, AI, and automation.
2. Installing Python and IDEs
You can install Python from python.org. For writing code, use IDLE, VS Code, PyCharm, or online platforms
like Replit.
3. Basic Syntax and Variables
Variables store data. Python uses indentation instead of braces. Statements are case-sensitive and lines
don't need semicolons.
4. Data Types in Python
Python has various data types: int, float, str, bool, list, tuple, set, dict. Use type() to check any variable type.
5. User Input and Output
Use input() to get user data, and print() to display output. Example:
name = input('Enter name: ')
print('Hello', name)
6. Operators
Arithmetic (+, -, *, /), Comparison (==, !=, >, <), Logical (and, or, not), Assignment (=, +=), and Bitwise
operators.
7. Conditional Statements
Use if, elif, and else to perform decisions in Python. Example:
Mastering Python: Beginner to Intermediate
if age > 18:
print('Adult')
8. Loops: for and while
Loops help in repeating tasks. 'for' is used with ranges or lists, 'while' repeats until a condition is False.
9. Functions
Functions help organize code. Use def to define a function. Example:
def greet():
print('Hello!')
10. Lists and List Operations
Lists are ordered collections. You can append, remove, and loop through lists. Example:
fruits = ['apple', 'banana']
11. Tuples and Sets
Tuples are immutable lists, and sets are unordered collections with unique elements.
12. Dictionaries
Dictionaries hold key-value pairs. Example:
student = {'name': 'John', 'age': 15}
13. String Manipulation
Strings can be sliced, joined, and formatted using methods like upper(), lower(), split(), and format().
14. Error Handling (Try-Except)
Mastering Python: Beginner to Intermediate
Use try-except blocks to handle runtime errors. Example:
try:
print(1/0)
except:
print('Error')
15. File Handling
Read and write files using open(). Example:
with open('file.txt', 'r') as f:
print(f.read())
16. OOP in Python
Python supports Object-Oriented Programming with classes and objects. Use class keyword to define
classes.
17. Modules and Packages
You can import code from other files using import. Built-in modules include math, random, datetime.
18. Useful Built-in Functions
Examples: len(), max(), min(), sum(), sorted(), isinstance().
19. Python Projects for Beginners
1. Calculator
2. Guess the Number
3. To-Do List
4. Alarm Clock
5. Quiz App
Mastering Python: Beginner to Intermediate
6. Chatbot
7. Dice Roller
8. Rock Paper Scissors
20. Next Steps
Once you know the basics, you can start learning libraries like NumPy, Pandas, Tkinter, and frameworks like
Django or Flask. For AI, move on to Scikit-Learn, TensorFlow, and OpenCV.
Mastering Python: Beginner to Intermediate
21. Sample Programs with Full Code
Simple Calculator:
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
op = input("Enter operation (+, -, *, /): ")
if op == "+":
print(num1 + num2)
elif op == "-":
print(num1 - num2)
elif op == "*":
print(num1 * num2)
elif op == "/":
print(num1 / num2)
else:
print("Invalid operation")
Guess the Number:
import random
number = random.randint(1, 10)
guess = int(input("Guess a number between 1 and 10: "))
if guess == number:
print("Correct!")
else:
print(f"Wrong! The number was {number}")
Even or Odd Checker:
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")
Pattern Printing:
Mastering Python: Beginner to Intermediate
for i in range(1, 6):
print("*" * i)
Simple Chatbot:
name = input("What's your name? ")
print("Hello", name)
mood = input("How are you feeling today? ")
if "good" in mood.lower():
print("That's great to hear!")
else:
print("Hope your day gets better!")