Python programming :from zero to pro
๐ Python Programming — The Complete Guide From Zero to Pro
๐ Introduction: What Is Python?
Python is a high-level, interpreted programming language that is:
- Easy to read and write (its syntax is like English)
- Extremely powerful — used in web development, AI, data science, automation, and more
- Free and open-source
- Supported by a large global community
๐ง Why Use Python?
- Simple syntax
- Large standard library
- Cross-platform (works on Windows, Mac, Linux)
- Used by companies like Google, Netflix, NASA, Facebook, IBM
๐ฐ PART 1: Getting Started
✅ Installing Python
- Visit python.org
- Download the latest version
- Install it and check with:
python --version
You can also use online editors like:
- Replit
- Google Colab
- [Jupyter Notebooks]
๐ PART 2: Python Fundamentals
๐ฆ 1. Print and Comments
print("Hello, world!") # This is a comment
๐ข 2. Variables and Data Types
name = "Alice" # string
age = 25 # integer
height = 5.7 # float
is_coder = True # boolean
Use type()
to check data type:
print(type(name))
๐งฎ 3. Operators
a + b # addition
a - b # subtraction
a * b # multiplication
a / b # division
a // b # floor division
a ** b # exponent
a % b # modulus
Comparison:
a == b, a != b, a > b, a < b
Logical:
and, or, not
๐ฏ 4. Input From Users
name = input("What is your name? ")
age = int(input("Enter your age: "))
๐ PART 3: Control Structures
✅ 1. If, Elif, Else
if age >= 18:
print("Adult")
elif age >= 13:
print("Teen")
else:
print("Child")
๐ 2. Loops
For Loop
for i in range(5):
print(i)
While Loop
x = 0
while x < 5:
print(x)
x += 1
Break and Continue
for i in range(10):
if i == 5:
break
if i % 2 == 0:
continue
print(i)
๐ง PART 4: Data Structures
✅ 1. Lists
fruits = ["apple", "banana", "mango"]
fruits.append("grape")
fruits[0] = "orange"
✅ 2. Tuples
t = (1, 2, 3)
✅ 3. Sets
s = {1, 2, 3, 2}
✅ 4. Dictionaries
person = {"name": "Tom", "age": 20}
person["age"] = 21
๐ง PART 5: Functions and Modules
✅ Defining Functions
def greet(name):
return f"Hello, {name}"
print(greet("Alice"))
✅ Arguments and Default Values
def greet(name="Guest"):
print("Hello,", name)
✅ Importing Modules
import math
print(math.sqrt(16))
Custom Module:
# in utils.py
def add(x, y):
return x + y
# in main.py
from utils import add
๐งฑ PART 6: Object-Oriented Programming (OOP)
✅ Class and Object
class Person:
def __init__(self, name):
self.name = name
def say_hi(self):
print("Hi, I'm", self.name)
p1 = Person("Alice")
p1.say_hi()
✅ Inheritance
class Student(Person):
def __init__(self, name, grade):
super().__init__(name)
self.grade = grade
✅ Encapsulation and Private Variables
class Bank:
def __init__(self):
self.__balance = 1000
def get_balance(self):
return self.__balance
⚙️ PART 7: File Handling
# Writing to file
with open("file.txt", "w") as f:
f.write("Hello")
# Reading from file
with open("file.txt", "r") as f:
print(f.read())
๐งฉ PART 8: Error Handling
try:
x = int("abc")
except ValueError:
print("That's not a number!")
finally:
print("Done!")
๐ ️ PART 9: Advanced Python Features
✅ List Comprehension
squares = [x**2 for x in range(10)]
✅ Lambda Functions
square = lambda x: x**2
print(square(5))
✅ Map, Filter, Reduce
from functools import reduce
nums = [1, 2, 3, 4]
print(list(map(lambda x: x*2, nums)))
print(list(filter(lambda x: x%2==0, nums)))
print(reduce(lambda x, y: x+y, nums))
✅ Generators
def countdown(n):
while n > 0:
yield n
n -= 1
๐งช PART 10: Useful Libraries
Purpose | Library | Description |
---|---|---|
Web Development | Flask, Django | Create websites |
Data Analysis | Pandas | Handle spreadsheets, tables |
Math | NumPy | Do fast calculations |
Graphs | Matplotlib, Seaborn | Draw charts |
Machine Learning | scikit-learn | Build AI models |
Deep Learning | TensorFlow, PyTorch | Advanced AI |
Games | pygame | Make games |
GUIs | tkinter, PyQt | Build apps |
Web Scraping | BeautifulSoup | Extract data from websites |
๐ฎ PART 11: Final Projects for Practice
- Calculator App
- To-Do List
- Simple Game (Snake or Tic-Tac-Toe)
- Weather App using API
- Chatbot using AI
- Web App using Flask
- Portfolio Website using Django
- YouTube Downloader
- Real-time Currency Converter
- Email Automation Bot
๐งญ PART 12: Tips to Become a Python Pro
- ✅ Code every day
- ✅ Solve problems on platforms like LeetCode, HackerRank
- ✅ Read Python documentation
- ✅ Contribute to GitHub projects
- ✅ Build real-world apps
- ✅ Stay updated with new libraries and trends
๐ฅ Conclusion
Python is a language that grows with you. You can use it for:
- Simple school projects
- Professional web development
- Advanced machine learning models
- Solving real-world problems
Comments
Post a Comment