Python Full Learning Guide With Codes
Python Full Learning Guide With Codes
Table of Contents
1. Introduction to Python
- Python Overview: Python is a high-level, interpreted programming language known for its simplicity
and readability.
- Why Python?: Python is versatile, used in web development, automation, AI, data science, and
more.
- Setting Up Python: Install Python from python.org or use package managers like Homebrew or
apt-get.
- Data Types:
int: 10
float: 3.14
str: "Hello"
- Operators:
x = 10
y=5
result = x + y # Output: 15
Example:
Example:
my_tuple = (1, 2, 3)
Example:
my_set = {1, 2, 3}
Example:
Example:
def greet(name):
Example:
add = lambda x, y: x + y
Example:
class Car:
self.make = make
self.model = model
def display(self):
print(f"{self.make} {self.model}")
Example:
try:
result = 10 / 0
except ZeroDivisionError:
print("Error: Division by zero is not allowed.") # Output: Error: Division by zero is not allowed.
Example:
file.write("Python is awesome!")
content = file.read()
Example:
import numpy as np
print(array) # Output: [1 2 3]
Example:
import pandas as pd
Example:
app = Flask(__name__)
@app.route("/")
def home():
Example:
def my_gen():
yield 1
yield 2
gen = my_gen()
print(next(gen)) # Output: 1
print(next(gen)) # Output: 2
Example:
class Meta(type):
pass