Skip to content

Latest commit

Β 

History

History
103 lines (77 loc) Β· 1.61 KB

File metadata and controls

103 lines (77 loc) Β· 1.61 KB

Python Basics

Basic concepts and examples for Python programming.


πŸ“₯ Installation

Linux (Debian/Ubuntu):

sudo apt update
sudo apt install python3 python3-pip

macOS:

brew install python

🧠 Key Concepts

  • Variable β€” a container for storing data.
  • Function β€” reusable block of code.
  • List β€” ordered, mutable collection.
  • Tuple β€” ordered, immutable collection.
  • Dictionary β€” key-value pairs.
  • Loop β€” repeat a block of code.
  • Condition β€” branching logic (if/else).
  • Module β€” file containing Python definitions.

✍️ Syntax Examples

Hello World:

print("Hello, world!")

Variables and Types:

name = "Anna"
age = 40
height = 1.65

List:

colors = ["red", "green", "blue"]
colors.append("purple")

Dictionary:

person = {"name": "Anna", "age": 40}
print(person["name"])

Function:

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

print(greet("Anna"))

Condition:

if age > 18:
    print("Adult")
else:
    print("Minor")

Loop:

for color in colors:
    print(color)

πŸ“š Further Topics

  • Working with files (open, read, write)
  • Exception handling (try, except)
  • Using external libraries (pip install)
  • Virtual environments (venv)
  • Object-Oriented Programming (OOP)

βœ… Practice Tip

  • Practice short scripts daily.
  • Use Python Tutor (pythontutor.com) to visualize code.
  • Try small challenges on sites like LeetCode, HackerRank, or Replit.