Code Explanation:
๐น 1. Importing asyncio
import asyncio
✅ Explanation:
Imports Python's asyncio module.
Used for asynchronous programming.
In this code, asyncio is imported but not actually used.
๐น 2. Defining an Async Function
async def func():
✅ Explanation:
async def creates an asynchronous function.
Also called a coroutine function.
⚠️ Important:
This is NOT a normal function.
Example:
def normal():
return 10
returns value immediately.
But:
async def func():
return 10
returns a coroutine when called.
๐น 3. Return Statement
return 10
✅ Explanation:
If the coroutine is executed,
it will eventually return:
10
But execution hasn't happened yet.
๐น 4. Calling the Async Function
x = func()
๐ What most beginners think:
x = 10
❌ Wrong
✅ What actually happens:
Calling:
func()
creates a coroutine object.
So:
x
stores:
<coroutine object func at ...>
๐น 5. Why Function Doesn't Execute?
Because async functions must be:
await func()
or
asyncio.run(func())
to actually run.
Without that:
func()
only creates a coroutine object.
๐น 6. Checking Type
print(type(x))
✅ Explanation:
Python checks type of:
x
which is a coroutine object.
๐น 7. Result
Output becomes:
<class 'coroutine'>
๐ฏ Final Output
<class 'coroutine'>

0 Comments:
Post a Comment