Python_ESP32_Basics
Python_ESP32_Basics
- Simple and Easy to Learn: Python has a clean and readable syntax, making it beginner-friendly.
- Interpreted Language: Executes code line by line, simplifying debugging.
- Dynamically Typed: No need to declare variable types explicitly.
- Object-Oriented: Supports OOP principles like encapsulation, inheritance, and polymorphism.
- Extensive Libraries: Provides libraries like NumPy, Pandas, TensorFlow, and more.
- Portability: Runs on multiple platforms without modifications.
- Numeric Types:
- Integer: x = 10
- Float: y = 10.5
- Complex: z = 3 + 4j
- String: s = "Hello, World!"
- List: l = [1, 2, 3, "apple"]
- Tuple: t = (1, 2, 3, "banana")
- Dictionary: d = {"name": "John", "age": 25}
- Set: s = {1, 2, 3, 4}
- Boolean: b = True
- Mutability: Lists are mutable (l.append(4)), tuples are immutable (t[1] = 5 gives an error).
- Performance: Tuples are faster than lists due to immutability.
- Usage: Lists are used for dynamic data, tuples for fixed data.
Example:
class Car:
def __init__(self, brand, model):
self.brand = brand
self.model = model
def display(self):
print(f"Car: {self.brand} {self.model}")
Example:
try:
x = 10 / 0
except ZeroDivisionError:
print("Cannot divide by zero!")
try:
file = open("non_existent.txt", "r")
except FileNotFoundError:
print("File not found!")
Example:
import machine
import time
led = machine.Pin(2, machine.Pin.OUT)
while True:
led.value(not led.value())
time.sleep(1)