Python_Learning_Guide
Python_Learning_Guide
Python is a popular, high-level programming language known for its simplicity and versatility. It is
widely used in web development, data science, AI, automation, and more.
# Installing Python:
1. Download Python from https://www.python.org/
2. Install it and ensure 'pip' (package manager) is installed.
3. Check installation using: python --version
# Basic Syntax:
- Print statement: print("Hello, World!")
- Variables: x = 10, name = "Anurag"
- Comments: # This is a comment
# Data Types:
- int, float, str, list, tuple, dict, set, bool
# Operators:
- Arithmetic: +, -, *, /, %
- Comparison: ==, !=, >, <, >=, <=
# Loops:
for i in range(5):
print(i) # Prints 0 to 4
while condition:
# Loop until condition is False
# Functions:
def greet(name):
return "Hello, " + name
print(greet("Anurag"))
Advanced Python Topics
def introduce(self):
return f"My name is {self.name}, and I am {self.age} years old."
p1 = Person("Anurag", 22)
print(p1.introduce())
# File Handling:
with open("file.txt", "w") as f:
f.write("Hello, Python!")
# Libraries:
import math
print(math.sqrt(16)) # Output: 4.0