Learn Python Programming - From Beginner to Advanced

Python is a high-level, interpreted, and object-oriented programming language. It is one of the easiest languages to read and write, making it perfect for beginners. Master Python with this comprehensive tutorial covering all aspects from installation to advanced concepts.

1. Introduction to Python Programming

Python, created by Guido van Rossum in 1991, is a versatile language used for web development, data science, machine learning, automation, and more. This general-purpose language is perfect for both beginners and experienced programmers.

2. Installing Python

To get started with Python, download the latest version from python.org and follow the installation guide for your operating system.

3. Writing Your First Python Program

print("Hello, World!")
    

4. Understanding Variables and Data Types

x = 10       # Integer
y = 3.14     # Float
name = "John"  # String
is_python_fun = True  # Boolean
print(name)
    

5. Conditional Statements in Python

age = 18
if age >= 18:
    print("You can vote.")
else:
    print("You cannot vote yet.")
    

6. Loops in Python (for & while)

# For loop example
for i in range(5):
    print("Hello", i)

# While loop example
count = 0
while count < 5:
    print("Counting:", count)
    count += 1
    

7. Functions in Python

def greet(name):
    print("Hello,", name)

greet("John")
    

8. Python Lists and Tuples

fruits = ["Apple", "Banana", "Cherry"]
print(fruits[0])  # Output: Apple

numbers = (1, 2, 3, 4)
print(numbers[2])  # Output: 3
    

9. Working with Python Dictionaries

student = {
    "name": "John",
    "age": 20,
    "course": "Python"
}
print(student["name"])  # Output: John
    

10. Object-Oriented Programming (OOP) in Python

class Person:
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def greet(self):
        print("Hello, my name is", self.name)

p = Person("John", 30)
p.greet()
    

11. File Handling in Python

# Writing to a file
with open("test.txt", "w") as f:
    f.write("Hello, this is a test file.")

# Reading from a file
with open("test.txt", "r") as f:
    print(f.read())
    

12. Using Python Modules and Libraries

import math
print(math.sqrt(16))  # Output: 4.0
    

13. Exception Handling in Python

try:
    x = 10 / 0
except ZeroDivisionError:
    print("Cannot divide by zero!")
    

14. Web Scraping with Python

import requests
from bs4 import BeautifulSoup

url = "https://www.example.com"
response = requests.get(url)
soup = BeautifulSoup(response.text, "html.parser")
print(soup.title.text)
    

15. Python for Data Science

import pandas as pd
import numpy as np

data = {
    "Name": ["John", "Ravi", "Emma"],
    "Age": [20, 22, 24]
}
df = pd.DataFrame(data)
print(df)
    

Conclusion

Learning Python is not only easy but also rewarding. To master Python, consistent practice and building small projects are essential. Start your journey today and unlock the power of Python programming for web development, data science, AI, and much more!