đ Welcome to the Python Section! Whether youâre just starting out or looking to master advanced techniques, this section has you covered. Itâs divided into three levelsâPython Basics, Intermediate, and Advancedâeach designed to build your skills progressively. From writing your first print()
statement to crafting powerful, reusable code with object-oriented design and advanced functions, youâll gain the tools and knowledge to tackle real-world programming tasks confidently.
Summary Table
Summary table of the Python section.
Basics
int |
10 |
Integer |
float |
3.14 |
Floating point number |
bool |
True , False |
Boolean value |
str |
"hello" |
String |
None |
None |
Null or no value |
Assignment |
x = 10 |
Assigns value to a variable |
Naming |
user_name = "Bob" |
Follows naming rules |
Reassignment |
x = x + 1 |
Updates variable value |
Multiple Assignment |
a, b = 1, 2 |
Assign multiple variables at once |
Dynamic Assignment |
x = 5 â x = "hello" |
Variable type can change during execution |
list |
[1, 2, 3] |
Mutable sequence |
tuple |
(1, 2) |
Immutable sequence |
set |
{1, 2, 3} |
Unordered unique elements |
dict |
{'key': 'value'} |
Key-value mapping |
Advanced
Basic function |
def my_function(): |
Define a reusable block of code |
Parameters |
def my_function(param): |
Input values to the function |
Return values |
return value |
Send a result back to the caller |
Default values |
def my_function(param="default"): |
Provide fallback values for parameters |
Keyword arguments |
my_function(arg2="value", arg1="val") |
Pass arguments by name |
*args |
def my_function(*args): |
Handle multiple positional arguments |
**kwargs |
def my_function(**kwargs): |
Handle multiple named keyword arguments |
Multiple return values |
return val1, val2 |
Return several values as a tuple |
Class definition |
class MyClass: |
Blueprint for creating objects |
Object creation |
obj = MyClass() |
Instantiate an object from a class |
__init__ method |
def __init__(self, ...) |
Set up initial object state |
Attributes |
self.attribute |
Store data in the object |
Methods |
def my_method(self): |
Function that operates on object data |
self keyword |
self.value = value |
Refers to the current instance of the class |
Class vs. instance attr |
MyClass.attr , self.attr |
Shared by all objects vs. unique per instance |
Inheritance |
class SubClass(SuperClass): |
Derive one class from another |
super() |
super().__init__(...) |
Call a method from the parent class |
Object identity |
obj1 == obj2 |
Compare references vs. internal values |
Basic import |
import module |
Load an entire module |
Import specific parts |
from module import item1, item2 |
Bring in only selected functions, classes, etc. |
Aliasing |
import module as alias |
Rename a module or function for convenience |
Aliased import (partial) |
from module import item as alias |
Rename a specific item during import |
Wildcard import |
from module import * |
Import everything from a module (not recommended) |
Custom module import |
import mymodule |
Import your own Python files as modules |
Conditional import |
if condition: import module |
Load a module only when needed |
Import error |
import nonexistent |
Happens when module or item is not found |
