Compare commits
2
Commits
582e2bcfe1
...
df793f5ae9
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
df793f5ae9 | ||
|
|
2ca60ee9f9 |
+12
-13
@@ -26,6 +26,7 @@
|
|||||||
#example for "When an instance method object is created by retrieving a user-defined function object from a class via one of its instances,
|
#example for "When an instance method object is created by retrieving a user-defined function object from a class via one of its instances,
|
||||||
#its __self__ attribute is the instance, and the method object is said to be bound. The new method’s __func__ attribute is the original function
|
#its __self__ attribute is the instance, and the method object is said to be bound. The new method’s __func__ attribute is the original function
|
||||||
#object."
|
#object."
|
||||||
|
"""""
|
||||||
class MyClass:
|
class MyClass:
|
||||||
def my_method(self):
|
def my_method(self):
|
||||||
print("Hello, world!")
|
print("Hello, world!")
|
||||||
@@ -42,10 +43,12 @@ print(method_object.__func__) # Output: <function MyClass.my_method at 0x...>
|
|||||||
|
|
||||||
# Calling the method through the method object
|
# Calling the method through the method object
|
||||||
method_object() # Output: Hello, world!
|
method_object() # Output: Hello, world!
|
||||||
|
"""""
|
||||||
|
|
||||||
#async def:
|
#async def:
|
||||||
# the async def syntax is used to define an asynchronous function, also known as a coroutine. An asynchronous function allows concurrent
|
# the async def syntax is used to define an asynchronous function, also known as a coroutine. An asynchronous function allows concurrent
|
||||||
# execution of multiple tasks by allowing the program to proceed to other tasks while waiting for certain operations to complete.
|
# execution of multiple tasks by allowing the program to proceed to other tasks while waiting for certain operations to complete.
|
||||||
|
"""""
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
async def my_coroutine():
|
async def my_coroutine():
|
||||||
@@ -55,7 +58,7 @@ async def my_coroutine():
|
|||||||
|
|
||||||
# Calling the coroutine
|
# Calling the coroutine
|
||||||
asyncio.run(my_coroutine())
|
asyncio.run(my_coroutine())
|
||||||
|
"""""
|
||||||
#Static method and class method:
|
#Static method and class method:
|
||||||
#In Python, static methods and class methods are two types of methods that can be defined within a class.
|
#In Python, static methods and class methods are two types of methods that can be defined within a class.
|
||||||
#Static methods:
|
#Static methods:
|
||||||
@@ -82,6 +85,7 @@ def main():
|
|||||||
number1 = 5
|
number1 = 5
|
||||||
number2 = 10
|
number2 = 10
|
||||||
sum_result = add_numbers(number1, number2)
|
sum_result = add_numbers(number1, number2)
|
||||||
|
breakpoint() # Set breakpoint here
|
||||||
product_result = multiply_numbers(sum_result, number2)
|
product_result = multiply_numbers(sum_result, number2)
|
||||||
print("Product:", product_result)
|
print("Product:", product_result)
|
||||||
|
|
||||||
@@ -89,21 +93,16 @@ if __name__ == "__main__":
|
|||||||
main()
|
main()
|
||||||
|
|
||||||
# question 3:
|
# question 3:
|
||||||
def foo():
|
|
||||||
a = 10
|
|
||||||
b = 20
|
|
||||||
return a + b
|
|
||||||
|
|
||||||
def bar():
|
def main():
|
||||||
x = 5
|
x = 5
|
||||||
y = 7
|
y = 2
|
||||||
return x * y
|
breakpoint()
|
||||||
|
result = x + y # Line of interest
|
||||||
result = foo() + bar()
|
|
||||||
print(result)
|
|
||||||
# In this example, using "Step Over" and "Step Into" may not yield different results, but the behavior is
|
|
||||||
# dependent on the implementation of the functions being called.
|
|
||||||
|
|
||||||
|
print(result)
|
||||||
|
|
||||||
|
main()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user