Introduction to Python
Welcome to the world of Python! If you're new to programming or just curious, Python is one of the easiest and most powerful languages to start with. Created by Guido van Rossum in the late 1980s, Python emphasizes readability and simplicity—think of it as English-like code that lets you focus on solving problems rather than wrestling with syntax.Why Learn Python?Run it with python hello.py in your terminal. Output: Hello, World!Core ConceptsLet's build from basics. Python is interpreted (runs line-by-line) and dynamically typed (no need to declare variable types upfront).1. Variables and Data TypesVariables store data. No var or int keywords needed.Common types: str (strings), int/float (numbers), bool, list (arrays like [1, 2, 3]), dict (key-value like {"key": "value"}).2. OperatorsMath: +, -, *, /, ** (power), % (modulo).Comparisons: ==, !=, >, <, and, or.3. Control Flow: If-Else and LoopsMake decisions and repeat tasks.If-Else:For Loop (iterate over lists):While Loop:4. FunctionsReusable code blocks. Define with def.Add parameters, defaults, or *args for flexibility.5. Lists and DictionariesList (mutable array):Dictionary:Next Steps
- Beginner-Friendly: Clean syntax, no semicolons or curly braces needed.
- Versatile: Used for web development (Django/Flask), data science (Pandas/NumPy), automation, AI/ML (TensorFlow), and more.
- Huge Community: Tons of libraries, tutorials, and jobs waiting.
- Fun and Fast: Write less code, get results quicker.
- Install Python: Download from python.org. Use version 3.12+ (avoid Python 2—it's retired).
- Run Code: Use the IDLE editor (comes with Python), or install VS Code for a better experience.
- Online Playground: Try Replit or Google Colab without installing anything.
python
print("Hello, World!")python
name = "Alice" # String (text)
age = 30 # Integer (whole number)
height = 5.7 # Float (decimal)
is_student = True # Boolean (True/False)
print(f"{name} is {age} years old.") # Output: Alice is 30 years old.python
x = 10
y = 3
print(x + y) # 13
print(x ** y) # 1000python
age = 18
if age >= 18:
print("Adult!")
else:
print("Minor.")python
fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
print(fruit.upper()) # APPLE, BANANA, CHERRYpython
count = 0
while count < 3:
print(count)
count += 1 # 0, 1, 2python
def greet(name):
return f"Hello, {name}!"
print(greet("Bob")) # Hello, Bob!python
numbers = [1, 2, 3]
numbers.append(4) # [1, 2, 3, 4]
print(numbers[0]) # 1 (0-indexed)python
person = {"name": "Eve", "age": 25}
print(person["name"]) # Eve- Practice: Solve challenges on LeetCode or HackerRank.
- Books: "Automate the Boring Stuff with Python" (free online).
- Courses: freeCodeCamp's Python section or Coursera's "Python for Everybody".
- Projects: Build a calculator, web scraper, or simple game.