1: Introduction to Python,
🐍 Post 1: Introduction to Python
Topics Covered:
Tokens: Keywords, Identifiers & Naming Rules, Operators
Data Types: Basic types, Mutable and Immutable
Input-Output Functions
🚩 What Are Tokens?
Tokens are the smallest building blocks of a Python program.
Main types:
Keywords: Reserved words with special meaning (e.g., if, else, while, for, def, class)
Identifiers: Names you give to variables, functions, classes, etc.
Rules:
Can use letters, digits, and underscores
Cannot start with a digit
Case-sensitive (Name and name are different)
Operators: Symbols that perform operations
Arithmetic: +, -, , /, //, %, *
Assignment: =, +=, -=, etc.
Comparison: ==, !=, <, >, <=, >=
Logical: and, or, not
🗂️ Data Types in Python
Python has several built-in data types.
Common types:
int (integer, e.g., 5)
float (decimal, e.g., 3.14)
str (string, e.g., "hello")
bool (True or False)
list (e.g., [1,- tuple (e.g., (1, 2, 3)`)
dict (dictionary, e.g., {"name": "Alice", "age": 20})
Mutable vs Immutable:
Mutable: Can change after creation (e.g., list, dict)
Immutable: Cannot change after creation (e.g., int, float, str, tuple)
🖥️ Input and Output in Python
Input: Use input() to get information from the user.
Example:python
name = input("Enter your name: ")
Output: Use print() to display information.
Example:python
print("Hello,", name)
💡 Example Code
python
# Getting user input and displaying output
name = input("Enter your name: ")
age = input("Enter your age: ")
print("Hello, " + name + "! You are " + age + " years old.")
📝 Practice Problem
Task:
Write a Python program that asks the user for their favorite color and then prints:
Your favorite color is {color}!
Starter code:
python
color = input("Enter your favorite color: ") print("Your favorite color is", color, "!")
🚀 Try It Out!
Use the interpreter below to practice: