Ad Code

Responsive Advertisement

🐍 Python Full Tutorial for beginner

 


🐍 Python Full Tutorial (Text Version)



Here is a complete Python tutorial in text form, covering everything from the basics to advanced topics. You can use this as a reference or learning guide.


1. Introduction to Python

  • High-level, interpreted language

  • Easy syntax and readability

  • Widely used in web, data science, AI, automation


2. Installation


3. Hello World

print("Hello, World!")

4. Variables and Data Types

x = 5             # int
name = "Alice"    # str
pi = 3.14         # float
is_valid = True   # bool

5. Input/Output

name = input("Enter your name: ")
print("Hello", name)

6. Operators

+  -  *  /  %  //  **     # Arithmetic
== != > < >= <=           # Comparison
and or not                # Logical

7. Conditional Statements

if age >= 18:
    print("Adult")
elif age > 13:
    print("Teen")
else:
    print("Child")

8. Loops

For Loop

for i in range(5):
    print(i)

While Loop

i = 0
while i < 5:
    print(i)
    i += 1

9. Functions

def greet(name):
    return f"Hello, {name}"

print(greet("Anurag"))

10. Lists

fruits = ["apple", "banana", "cherry"]
fruits.append("mango")
print(fruits[1])

11. Tuples

point = (10, 20)
print(point[0])

12. Dictionaries

student = {"name": "Anurag", "age": 21}
print(student["name"])

13. Sets

nums = {1, 2, 3, 2}
print(nums)  # No duplicates

14. String Methods

s = "hello"
print(s.upper())
print(s.replace("l", "x"))

15. List Comprehension

squares = [x*x for x in range(10)]

16. Exception Handling

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

17. Classes and Objects

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

    def greet(self):
        print("Hi", self.name)

p = Person("Anurag")
p.greet()

18. File Handling

with open("file.txt", "r") as file:
    print(file.read())

with open("file.txt", "w") as file:
    file.write("Hello World")

19. Modules and Packages

import math
print(math.sqrt(16))

Custom module:

# mymodule.py
def add(a, b):
    return a + b

# main.py
from mymodule import add

20. Useful Libraries

  • numpy: Numerical computing

  • pandas: Data analysis

  • matplotlib: Plotting

  • flask: Web development

  • requests: HTTP requests


21. Virtual Environments

python -m venv env
source env/bin/activate  # or env\Scripts\activate on Windows

22. Decorators

def decorator(func):
    def wrapper():
        print("Before")
        func()
        print("After")
    return wrapper

@decorator
def hello():
    print("Hello!")

hello()

23. Generators

def gen():
    yield 1
    yield 2

for x in gen():
    print(x)

24. Lambda Functions

square = lambda x: x * x
print(square(5))

25. Working with APIs

import requests
response = requests.get("https://api.github.com")
print(response.json())

If you'd like this in a PDF, DOCX, or Notion format, let me know — I can export or generate it for you.

Would you like a version with practice questions, projects, or step-by-step tutorials next?

Post a Comment

0 Comments