๐ 1. Introduction to Python
Python is a high-level, interpreted programming language known for its readability and simplicity. It supports multiple paradigms including procedural, object-oriented, and functional programming.
๐ง Key Features:
- Easy syntax, close to English
- Large standard library
- Cross-platform compatibility
- Widely used in web development, data science, automation, AI, and embedded systems (via MicroPython)
๐ 2. Python Getting Started
To begin coding in Python:
- Install Python from python.org
- Use an IDE like VS Code, PyCharm, or Jupyter Notebook
- Run scripts via terminal or interactive shell
๐งช Example:
print("Hello, QSignal!")
โ๏ธ 3. Python Syntax
Python uses indentation (whitespace) to define code blocks instead of braces {}.
๐งช Example:
if 5 > 2:
print("Five is greater than two!")
โ Indentation is mandatory. Improper spacing will raise an error.
๐ฌ 4. Python Comments
Comments help explain code and are ignored during execution.
๐งช Example:
# This is a single-line comment
print("Hello") # Inline comment
"""
This is a multi-line comment
or docstring used for documentation
"""
๐ฆ 5. Python Variables
Variables store data. Python is dynamically typedโno need to declare types.
๐งช Example:
x = 10 # Integer
name = "Karthikeyan" # String
pi = 3.14 # Float
๐ 6. Python Data Types
Common built-in types:
- int, float, str, bool
- list, tuple, dict, set
๐งช Example:
a = 5 # int
b = 3.14 # float
c = "QSignal" # str
d = True # bool
Use type() to check:
print(type(c)) # <class 'str'>
๐ข 7. Python Numbers
Python supports:
- int: whole numbers
- float: decimal numbers
- complex: imaginary numbers
๐งช Example:
x = 10
y = 3.5
z = 2 + 3j
Use int(), float() to convert types.
๐ 8. Python Casting
Casting means converting one data type to another.
๐งช Example:
a = int("5") # Converts string to int
b = float(10) # Converts int to float
c = str(3.14) # Converts float to string
๐ค 9. Python Strings
Strings are sequences of characters enclosed in quotes.
๐งช Example:
text = "Hello, QSignal"
print(text[0]) # H
print(text[-1]) # l
print(text[0:5]) # Hello
print(len(text)) # Length
๐ง Common Methods:
text.upper(), text.lower(), text.strip(), text.replace(), text.split()
โ 10. Python Booleans
Booleans represent truth values: True or False.
๐งช Example:
a = True
b = False
print(5 > 3) # True
print(5 == 3) # False
Used in conditions and loops.
โ 11. Python Operators
Operators perform operations on variables and values.
๐ง Types:
- Arithmetic: +, -, , /, %, *, //
- Comparison: ==, !=, >, <, >=, <=
- Logical: and, or, not
- Assignment: =, +=, -=, etc.
๐งช Example:
x = 5
y = 3
print(x + y) # 8
print(x > y and y < 4) # True
๐ 12. Python Lists
Lists are ordered, mutable collections.
๐งช Example:
fruits = ["apple", "banana", "cherry"]
print(fruits[1]) # banana
fruits.append("orange") # Add item
fruits.remove("apple") # Remove item
๐ง Useful Methods:
fruits.sort(), fruits.reverse(), fruits.insert(1, "grape")