PEARLS OF WISDOM
- The channel has uploads everyday in the form of 15sec - 45sec motivation #shorts
- The channel also uploads long videos which are 3min - 5min, on real success stories, motivational experiments every Monday.
A REST API is like having a conversation with a web server using the HTTP protocol. You send an HTTP request, and the server replies with an HTTP response.
KEY COMPONENTS IN A REST API INTERACTION ARE
A. HTTP Request: In simple words it means: You Ask for Something
Every request includes:
GET
, POST
, PUT
, DELETE
)/users
, /posts/1
)application/json
)POST
, PUT
, etc.)Example:
B. HTTP Response: Server Replies
A response includes:
200 OK
, 404 Not Found
, 201 Created
)What Is urllib
?
urllib
is part of Python’s standard library and includes submodules like:
urllib.request
: for opening and reading URLsurllib.parse
: for encoding query parametersurllib.error
: for handling exceptionsNo installation needed — it’s ready to go out of the box!
We shall use this library to work with Rest APIs
Please refer to the following trinket to see an example on GET, POST, PUT, DELETE operations in Python
Python supports rich object-oriented programming (OOP) features that promote modularity, scalability, and readability. In this article, we’ll explore core OOP concepts using Python’s syntax and conventions—ideal for building GUI apps, REST APIs, and creative projects.
self : here indicates the current context of the object created
ClassName.<static_member>
Lambdas in Python are like mini-functions without a name, perfect for short, quick operations—think of them as the “Post-it notes” of the coding world: compact, purposeful, and disposable.
What Is a Lambda Function?
A lambda in Python is an anonymous function defined using the lambda
keyword. It’s used when you need a simple function for a short period and don’t want to formally define it with def
.
Syntax Breakdown
lambda arguments: expression
def traditional_square(num):
return num * num
square = lambda num: num * num #defined the function
print(square(5))
Common Use Cases
Use Case | Example |
---|---|
With |
|
With |
|
With |
|
Quick function |
|
What Is a Dictionary in Python?
A dictionary is a built-in data type that lets you store data in key-value pairs. Instead of accessing values by a number (like in a list), you access them by their label.
Syntax
When to Use Dictionaries
Use them when:
Common methods used with dictionaries
See the following code and try it yourself
In the earlier article, we have seen the use of global, and the different flavors of functions in Python.
Let''s combine them and use comprehensions to reduce the total lines of code.
In Python, comprehensions are a concise and expressive way to create new sequences—like lists, sets, dictionaries, or generators—from existing iterables. They let you write elegant one-liners that would otherwise require multiple lines of loops and conditionals.
Comprehensions work like the Arabic language, read from right-to-left
modify(old_emp, new_emp)
, the execution happens in a sequential top-to-down manner.modify_smart(old,new)
, the same execution happens in one-line from right to leftLet's highlight the comprehension in the modify_smart()
for emp in company_employees
: Iterate over each employee name in the list.new if emp == old else emp
: If the employee name matches old
, replace it with new
; otherwise, keep it unchanged.Global
keywordThe global
keyword is used to declare that a variable inside a function refers to a variable defined in the global scope—outside the function. Without it, Python treats variables assigned inside a function as local by default.
Each function runs in its own scope. Any changes made in it are confined within the scope of the function.
Hence, if a variable name is declared outside the function and is later modified inside the function, the modifications made inside the function will not reflect in the variable declared outside the function.
This functions similar to having a secret-lingo within friends. Outside the friends circle the same secret-lingo will not be shared. Modification to outer variables inside the functions also work in a similar way.
🔍 Understanding the above code
secret_lingo
is a global string that holds our "secret message".update_lingo()
uses global secret_lingo
to modify it from inside the function.reveal_lingo()
just prints the current value.