
- Main
- Catalog
- Computer science
- Python Learning
Channel statistics
if x = 5: # ❌ Error{}
👉 = is assignment
👉 == is comparison
2️⃣ Not Understanding Mutable Objects 🔗
a = [1, 2]
b = a
b.append(3)
print(a){}
Output: [1, 2, 3]
👉 Both changed 😳
👉 Because they point to SAME object
3️⃣ Forgetting Indentation ⚠️
if True:
print("Hello") # ❌{}
👉 Python depends on indentation
👉 One mistake → code breaks
4️⃣ Using is Instead of == 🤯
a = 1000
b = 1000
print(a is b){}
👉 Might return False
👉 Because is checks memory, not value
5️⃣ Modifying List While Looping 🔥
nums = [1, 2, 3]
for x in nums:
nums.remove(x){}
👉 Leads to unexpected bugs
👉 Loop skips elements
💡 Key Idea
Most bugs in Python
come from misunderstanding how it works internally 🚀int, float, str, bool, list, dict).
3. Function: A block of organized, reusable code that is used to perform a single, related action. Functions provide better modularity for your application and a high degree of code reusing.
4. Method: A function that is associated with an object or a class. It operates on the data (attributes) of that object.
5. Class: A blueprint for creating objects. It defines a set of attributes (data) and methods (functions) that characterize any object created from it.
6. Object: An instance of a class. It is a collection of data (attributes) and functions (methods) that operate on that data.
7. Module: A file containing Python definitions and statements. The file name is the module name with the suffix .py appended. Modules allow you to logically organize your Python code.
8. Package: A Python module can be grouped into a package. A package is a directory of Python modules containing an __init__.py file (which can be empty). Packages allow for a hierarchical structuring of the module namespace.
9. Interpreter: The program that reads and executes Python code. Python code is not compiled to machine code directly; it is compiled to bytecode, which is then interpreted.
10. Syntax: The set of rules that defines the combinations of symbols that are considered to be correctly structured programs in a particular language.
11. Indentation: Python uses whitespace (spaces or tabs) to define code blocks (e.g., inside loops, functions, or conditional statements) rather than braces like in many other languages.
12. List: An ordered, mutable (changeable) collection of items. Items can be of different data types.
13. Tuple: An ordered, immutable (unchangeable) collection of items. Like lists, tuples can contain items of different data types.
14. Dictionary: An unordered collection of key-value pairs. Keys must be unique and immutable (e.g., strings, numbers, tuples), while values can be of any data type.
15. String: An immutable sequence of characters, used to represent text data.
16. Loop: A control flow statement that allows code to be executed repeatedly. Common loops are for and while.
17. Conditional Statement: Statements that perform different computations or actions depending on whether a programmer-specified boolean condition evaluates to true or false. Common are if, elif, else.
18. Exception Handling: A mechanism to handle runtime errors or unexpected events gracefully, preventing the program from crashing. Uses try, except, finally blocks.
19. Library/Framework: A collection of pre-written code (functions, classes) that developers can use to perform common tasks without writing the code from scratch. Examples: NumPy, Pandas, Django, Flask.
20. IDE (Integrated Development Environment): A software application that provides comprehensive facilities to computer programmers for software development. It typically includes a code editor, debugger, and build automation tools. Examples: VS Code, PyCharm.@ Syntax
Instead of writing say_hello = my_decorator(say_hello), Python gives us a beautiful shortcut: the @ symbol. Placing @decorator_name above a function automatically wraps it.
🐍 Practical Code Example: A Simple Timer
Let's create a decorator that measures how long a function takes to run.
import time
# 1. Define the decorator
def timer_decorator(func):
def wrapper(*args, **kwargs): # The 'wrapper' adds the new behavior
start_time = time.time()
result = func(*args, **kwargs) # Execute the original function
end_time = time.time()
print(f"⏱️ {func.__name__} took {end_time - start_time:.4f} seconds.")
return result
return wrapper
# 2. Use the decorator
@timer_decorator
def heavy_computation():
print("Computing...")
time.sleep(1.5) # Simulate a long task
print("Done!")
# 3. Call the function
heavy_computation()
{}
4. Why Use Decorators?
- Code Reusability: Write the logic once (like logging) and apply it to 50 different functions.
- Separation of Concerns: Keep your main logic clean. The "extra" stuff (security, timing) stays in the decorator.
- DRY Principle: Prevents you from copy-pasting the same setup/teardown code into every function.
🎯 Today's Goal (What you should do)
✔️ Understand that decorators "wrap" functions to add functionality
✔️ Master the @ syntax for applying decorators
✔️ Learn how to pass arguments to wrapped functions using *args and *kwargs
✔️ Identify common use cases: Logging, Timing, and Authentication
print(bool(0))
print(bool(""))
print(bool([])){}
Output: False False False
👉 Empty or zero-like values → False
2️⃣ Truthy Values ✅
Everything else is considered True:
print(bool(1))
print(bool("Hello"))
print(bool([1, 2])){}
Output: True True True
👉 Non-empty values → True
3️⃣ Why This Matters ⚡️
name = ""
if name:
print("Has value")
else:
print("Empty"){}
Output: Empty
👉 No need to write if name != ""
4️⃣ Common Mistake 🚫
if list == []: # ❌{}
👉 Better way:
if not list: # ✅{}
💡 Key Idea
Python doesn’t just check True/False
It checks if something is empty or not 🧠Reviews channel
9 total reviews
- Added: Newest first
- Added: Oldest first
- Rating: High to low
- Rating: Low to high
Catalog of Telegram Channels for Native Placements
Python Learning is a Telegram channel in the category «Интернет технологии», offering effective formats for placing advertising posts on TG. The channel has 5.9K subscribers and provides quality content. The advertising posts on the channel help brands attract audience attention and increase reach. The channel's rating is 22.7, with 9 reviews and an average score of 5.0.
You can launch an advertising campaign through the Telega.in service, choosing a convenient format for placement. The Platform provides transparent cooperation conditions and offers detailed analytics. The placement cost is 8.4 ₽, and with 22 completed requests, the channel has established itself as a reliable partner for advertising on Telegram. Place integrations today and attract new clients!
You will be able to add channels from the catalog to the cart again.
Комментарий