Day 8–10 Python
Day 8 TO 10 /20
For days 8 to 10 of your Python learning journey, you should continue working on your small project and expand upon it. You can also start exploring more advanced topics in Python such as decorators, generators, and asynchronous programming.
Here are a few examples of concepts you might encounter during these days, along with some code snippets that demonstrate how they work:
Decorators:
def bold(func):
def wrapper(*args, **kwargs):
return "<b>" + func(*args, **kwargs) + "</b>"
return wrapper
@bold
def greet(name):
return "Hello, " + name
print(greet("Alice")) # "<b>Hello, Alice</b>"
Generators:
def countdown(n):
while n > 0:
yield n
n -= 1
for i in countdown(5):
print(i)
# Output:
# 5
# 4
# 3
# 2
# 1
Asynchronous programming:
import asyncio
async def main():
await asyncio.sleep(1)
print("Done sleeping")
asyncio.run(main()) # prints "Done sleeping" after 1 second
I hope that these Python Preparation Plans will help you enhance your interest in programming as well as python and then all python topics. Please feel free to provide insightful remarks in the space below.