I have been working as a software developer since 2019. I have started coding since 2014. I have watched a lot of tutorials and read many books. But today I understood "Generator" properly. Thank you sir, you are really great. ❤❤
51:00 So, basically what I've understood, "yield" is kind of like the "static" keyword which is used in c/c++. when we say, "static int a = 5;" inside of a function & we call that function multiple times or call that function using a loop, that static variable "a" saves it's previous state in memory & performs the next tasks with it's previous state every single time function is called. not saying they are the same. But yeah, i found it familiar.
To avoid those recurring decimal in solution_04, we can use round() method to avoid those recurring decimals and can convert it to 1 , 2 or any decimal place you like. Source Code: import math def circle_stats(radius): area = round(math.pi * radius ** 2,2) circumference = round(2 * math.pi * radius,2) return area, circumference a , c = circle_stats(3) print("Area: ", a, "Circumference: ", c)
import math def circle(radius): area = round(math.pi*(radius**2),2) circumference = round((2 * math.pi * radius) ,2); return area , circumference; r = int(input("Enter Radius: ")) a , c = circle(r) print("The Area is: ",a) print("The Circumference is: ",c)
19:45 Precision can be achieved using round() function as given below: def circle_stats(radius): area=math.pi*radius**2 circumference=2*math.pi*radius return *round(area,2),round(circumference,2)* print(circle_stats(5)) (78.54, 31.42) *Further, can we round off multiple values at once instead of doing separately for each one?*
Learning Python day 10 - present sir 00:03 Introduction to functions in Python 02:16 Learning functions in Python with confidence 06:06 Variables and function parameters in Python 08:07 Using the return keyword to output a result from a function in Python 12:05 Polymorphism in Python functions 14:17 Creating functions to return multiple values in Python 18:22 Returning multiple values from a function in Python 20:22 Creating and handling functions in Python. 24:13 Creating a function to compute the cube of a number 25:53 Understanding function definitions in Python 29:25 Using Python's special parameters to handle input values efficiently. 31:21 Printing and investigating errors in Python functions 34:53 Functions in Python and their usage with keyword arguments 36:52 Understanding function definitions and arguments in Python 40:42 Using formatting strings to print values in Python functions 42:33 Creating a function to generate even numbers with a limit in Python. 46:37 Understanding function implementation in Python 48:38 Functions in Python use yield to produce a sequence of values 52:16 Creating a function to calculate factorial and understanding recursion 54:18 Recursive approach to calculate factorial in Python 57:56 Learned the key concepts of functions in Python
51:07 I have worked on some personal projects in deep learning and one use case of yield is handling huge amount of datasets where we need to fetch a batch of numbers from the datasets to perform calculation of gradients during backpropogation which is a way to optimized neural networks loss calculations
The video script covers various topics related to functions in Python, including calling functions, polymorphism, handling values, generator functions, recursion, and function parameters. It also introduces upcoming topics in a new series on Python programming with a focus on making videos with tea. Introduction to Python Functions and Syntax Introducing a new series on Python with a focus on making videos with tea. Upcoming topics include functions, loops, and confidence in Python programming. Explaining the basics of function syntax and parameters in Python. Understanding Python Function Parameters and Return Values Explaining the concept of placeholders and parameters in Python functions. Demonstrating how to use multiple parameters and return values in Python functions. Understanding the process of adding and printing multiple values in Python functions. Understanding Function Execution in Python Explaining how to call a function and provide two numbers Discussing the value and print function in Python Understanding polymorphism and function multiplication in Python Understanding Function Parameters and Return Values in Python Execution stops if area is not calculated Hold the area and calculate the circumference Learning about function parameters and return values Understanding Python Functions and Syntax Basic definition of under solution function Defining and using the add method with parameters Explaining the concept of nested functions and the pass keyword Handling Multiple Arguments in Python Functions The speaker discusses handling multiple arguments in Python functions. He explains how to use asterisk (*) to handle an arbitrary number of arguments. The speaker demonstrates creating a function that accepts any number of keyword arguments. Understanding the Syntax of Print Function in Python Explaining the concept of value and how to use it in Python. Demonstrating the syntax and usage of the print function with parameters. Understanding the handling of arguments and values in the print function. Understanding Python Generator Functions and Yield Concept Learning how to handle values and pairs within Python generator functions. Exploring the yield concept and its significance from a memory perspective. Understanding the usage of range and skip count within Python generator functions. Understanding the Implementation of Yield and Recursion in Python Explaining the process of creating a list using the append method Implementing the yield method to add values to the list Introduction to the concept of recursion and its application in calculating factorials Understanding Recursion and Factorial Calculation Recursion involves calling a function from within itself Factorial calculation using recursion involves breaking down the problem and solving it step by step Focus on developing a good exit strategy when working with recursion
20:12 1) first method Below formatted variable will be displayed with 5 decimal values formatted = "{:.5f}".format(9.999875698989) print(formatted) # output : 9.99988 And suppose we write like this formatted = "{:.3f}".format(9.999875698989) print(formatted) # output : 10 Then it will return 10 as output. 2) using round() In this function we will pass two parameters, first is our value or variable and second is how many decimal values we want. Example_1: Number = 5.375829473 print(round(Number,2) # output : 5.36 Example_2 : print(round(5.53627894,2)) # output : 5.53
Thanks for such a simplistic, professional and in-depth content for question 6(26:06), I used this: cube = lambda user_in: user_in ** 3 user_in = float(input('Input a number for cube')) print(cube(user_in))
my mind is just tuned with all your words, they just directly print into my mind i just simply run those without any errors , i think you have hacked my mind....grate full to u sir
00:00 Introduction to Python Functions and Syntax 05:54 Understanding Python Function Parameters and Return Values 11:47 Understanding Function Execution in Python 17:41 Understanding Function Parameters and Return Values in Python 23:33 Understanding Python Functions and Syntax 29:30 Handling Multiple Arguments in Python Functions 35:24 Understanding the Syntax of Print Function in Python 41:17 Understanding Python Generator Functions and Yield Concept 47:12 Understanding the Implementation of Yield and Recursion in Python 53:06 Understanding Recursion and Factorial Calculation 53:06Recursion involves calling a function from within itself 54:11Factorial calculation using recursion involves breaking down the problem and solving it step by step 56:04Focus on developing a good exit strategy when working with recursion
20:11 import math def circlestat(radius): area = math.pi * radius **2 circumference = 2* math.pi *radius return area ,circumference a,b = circlestat(6) a= round(a,3) b=round(b,3) print("area: ",a , "circumference",b) round() is used to take those values upto 2 or 3 decimal places only
We can use the f-strings functionality. For example, if we want precision up-to 2 digits, then we can type: - print(f"Area : {a:.2f} Circumference: {c:.2f}")
Now I'm feeling that I'm diving into the internal working of python. The way he explains every topics that is phenomenal. I'm regularly waiting for his python series videos. Thanks sir for making this wonderful series.
00:03 Introduction to functions in Python 02:16 Learning functions in Python with confidence 06:06 Variables and function parameters in Python 08:07 Using the return keyword to output a result from a function in Python 12:05 Polymorphism in Python functions 14:17 Creating functions to return multiple values in Python 18:22 Returning multiple values from a function in Python 20:22 Creating and handling functions in Python. 24:13 Creating a function to compute the cube of a number 25:53 Understanding function definitions in Python 29:25 Using Python's special parameters to handle input values efficiently. 31:21 Printing and investigating errors in Python functions 34:53 Functions in Python and their usage with keyword arguments 36:52 Understanding function definitions and arguments in Python 40:42 Using formatting strings to print values in Python functions 42:33 Creating a function to generate even numbers with a limit in Python. 46:37 Understanding function implementation in Python 48:38 Functions in Python use yield to produce a sequence of values 52:16 Creating a function to calculate factorial and understanding recursion 54:18 Recursive approach to calculate factorial in Python 57:56 Learned the key concepts of functions in Python Crafted by Merlin AI.
sir aapko killvish ko bhi add karna chahiye tha main villan ki tor pe wese is tarike se python ke function ko sikh kar ke maza hi aa gaya love from mumbai sir ji ❤❤
# Function Returning Multiple values # Problem : Create a function that returns both the area and circumference of a circle given its radius. import math def circle_stats(radius): area = math.pi * radius ** 2 circumference = 2 * math.pi * radius return area , circumference a , c = circle_stats (3) print("Area: ", round(a,2), "Circumference: ",round(c,2)) #Assignment
people who didn't understood how actually the yield program in solution 9 works, read below to understand.... Function Definition: The program starts by defining a generator function named even_gen. This function takes one parameter limit, which represents the upper limit of the range of even numbers to generate. Inside the function, a for loop is used to iterate over a range starting from 2 (the first even number) up to and including the specified limit, incrementing by 2 in each step. Within the loop, the yield keyword is used to yield (or generate) each even number. Generator Function Execution: When the even_gen function is called with an argument (e.g., even_gen(10)), it doesn't start executing immediately. Instead, it returns a generator object. The generator object represents an iterable sequence of even numbers based on the specified limit. Iteration using a for loop: The generator object returned by even_gen is iterated over using a for loop. In each iteration, the for loop retrieves the next value from the generator using the next() function implicitly. The next() function resumes the execution of the generator function until the next yield statement is encountered. The value yielded by the yield statement (an even number) is assigned to the variable num, and the loop body is executed. Printing Even Numbers: Inside the loop body, each even number generated by the even_gen function is printed using the print statement. In this case, the even numbers from 2 to 10 are printed, as the limit argument passed to even_gen is 10. End of Iteration: The for loop continues iterating until there are no more values to yield from the generator. Once all the even numbers within the specified range are yielded and processed, the loop terminates. Program Termination: After the loop finishes execution, the program ends as there is no more code to execute. In summary, the program defines a generator function that yields even numbers within a specified range, and then iterates over the generated numbers, printing each one. This approach efficiently generates and processes even numbers one at a time, conserving memory compared to storing all even numbers in a list.
def area_circumference(a): area = (3.14)*(a)*(a) circumference =2*3.14*(a) print("area=",area) print("circumference=",circumference) a = float(input("enter the radius:")) (area_circumference(a))
20:23 # Use string formatting to round to 2 decimal places print("Area: {:.2f}, Circumference: {:.2f}".format(a, c)) # Use the round() function to round to 2 decimal places print("Area:", round(a, 2), "Circumference:", round(c, 2))
I know some basics of python but whenever I watch your videos , I consistently gain new insights and knowledge.
But your code shows errors lol
19:52
import math
def circle_stats(radius):
area = math.pi* 2 * radius**2
circumference = 2 * math.pi * radius
return area, circumference
a, c = circle_stats(3)
print(f"Area = {round(a,2)}
Circumference = {round(c,2)}")
f stream print(f"Area={area: .2f},circumference={circumference:.2f}")
I have been working as a software developer since 2019. I have started coding since 2014. I have watched a lot of tutorials and read many books. But today I understood "Generator" properly. Thank you sir, you are really great. ❤❤
Solution of 20:26 :
print(“area:”,round(a,2),”circumference”,round(b,2))
Thanks buddy..........
51:00
So, basically what I've understood,
"yield" is kind of like the "static" keyword which is used in c/c++.
when we say, "static int a = 5;" inside of a function & we call that function multiple times or call that function using a loop, that static variable "a" saves it's previous state in memory & performs the next tasks with it's previous state every single time function is called.
not saying they are the same. But yeah, i found it familiar.
To avoid those recurring decimal in solution_04, we can use round() method to avoid those recurring decimals and can convert it to 1 , 2 or any decimal place you like.
Source Code:
import math
def circle_stats(radius):
area = round(math.pi * radius ** 2,2)
circumference = round(2 * math.pi * radius,2)
return area, circumference
a , c = circle_stats(3)
print("Area: ", a, "Circumference: ", c)
import math
def circle(radius):
area = round(math.pi*(radius**2),2)
circumference = round((2 * math.pi * radius) ,2);
return area , circumference;
r = int(input("Enter Radius: "))
a , c = circle(r)
print("The Area is: ",a)
print("The Circumference is: ",c)
in your code you are not defined how many precision after point like 2,3or 4
19:45
Precision can be achieved using round() function as given below:
def circle_stats(radius):
area=math.pi*radius**2
circumference=2*math.pi*radius
return *round(area,2),round(circumference,2)*
print(circle_stats(5))
(78.54, 31.42)
*Further, can we round off multiple values at once instead of doing separately for each one?*
either you can go with this " print("Area:",f"{area:.2f}
circumference:{circum:.2f}") "
amazing video :)
TimeStamp:-
20:24
Precision upto x decimal places can be achieved by using
round(variable_name,x)
Learning Python day 10 - present sir
00:03 Introduction to functions in Python
02:16 Learning functions in Python with confidence
06:06 Variables and function parameters in Python
08:07 Using the return keyword to output a result from a function in Python
12:05 Polymorphism in Python functions
14:17 Creating functions to return multiple values in Python
18:22 Returning multiple values from a function in Python
20:22 Creating and handling functions in Python.
24:13 Creating a function to compute the cube of a number
25:53 Understanding function definitions in Python
29:25 Using Python's special parameters to handle input values efficiently.
31:21 Printing and investigating errors in Python functions
34:53 Functions in Python and their usage with keyword arguments
36:52 Understanding function definitions and arguments in Python
40:42 Using formatting strings to print values in Python functions
42:33 Creating a function to generate even numbers with a limit in Python.
46:37 Understanding function implementation in Python
48:38 Functions in Python use yield to produce a sequence of values
52:16 Creating a function to calculate factorial and understanding recursion
54:18 Recursive approach to calculate factorial in Python
57:56 Learned the key concepts of functions in Python
51:07 I have worked on some personal projects in deep learning and one use case of yield is handling huge amount of datasets where we need to fetch a batch of numbers from the datasets to perform calculation of gradients during backpropogation which is a way to optimized neural networks loss calculations
The video script covers various topics related to functions in Python, including calling functions, polymorphism, handling values, generator functions, recursion, and function parameters. It also introduces upcoming topics in a new series on Python programming with a focus on making videos with tea.
Introduction to Python Functions and Syntax
Introducing a new series on Python with a focus on making videos with tea.
Upcoming topics include functions, loops, and confidence in Python programming.
Explaining the basics of function syntax and parameters in Python.
Understanding Python Function Parameters and Return Values
Explaining the concept of placeholders and parameters in Python functions.
Demonstrating how to use multiple parameters and return values in Python functions.
Understanding the process of adding and printing multiple values in Python functions.
Understanding Function Execution in Python
Explaining how to call a function and provide two numbers
Discussing the value and print function in Python
Understanding polymorphism and function multiplication in Python
Understanding Function Parameters and Return Values in Python
Execution stops if area is not calculated
Hold the area and calculate the circumference
Learning about function parameters and return values
Understanding Python Functions and Syntax
Basic definition of under solution function
Defining and using the add method with parameters
Explaining the concept of nested functions and the pass keyword
Handling Multiple Arguments in Python Functions
The speaker discusses handling multiple arguments in Python functions.
He explains how to use asterisk (*) to handle an arbitrary number of arguments.
The speaker demonstrates creating a function that accepts any number of keyword arguments.
Understanding the Syntax of Print Function in Python
Explaining the concept of value and how to use it in Python.
Demonstrating the syntax and usage of the print function with parameters.
Understanding the handling of arguments and values in the print function.
Understanding Python Generator Functions and Yield Concept
Learning how to handle values and pairs within Python generator functions.
Exploring the yield concept and its significance from a memory perspective.
Understanding the usage of range and skip count within Python generator functions.
Understanding the Implementation of Yield and Recursion in Python
Explaining the process of creating a list using the append method
Implementing the yield method to add values to the list
Introduction to the concept of recursion and its application in calculating factorials
Understanding Recursion and Factorial Calculation
Recursion involves calling a function from within itself
Factorial calculation using recursion involves breaking down the problem and solving it step by step
Focus on developing a good exit strategy when working with recursion
You are the best teacher,❤ in this platform,,
Kudos to you, sir, for explaining yield in such a simplified manner, as if you were explaining it to a 5-years-old.
Sir, apke help se hum sab to hopeful hain... Thanks Alot!
20:12
1) first method
Below formatted variable will be displayed with 5 decimal values
formatted = "{:.5f}".format(9.999875698989)
print(formatted) # output : 9.99988
And suppose we write like this
formatted = "{:.3f}".format(9.999875698989)
print(formatted) # output : 10
Then it will return 10 as output.
2) using round()
In this function we will pass two parameters, first is our value or variable and second is how many decimal values we want.
Example_1:
Number = 5.375829473
print(round(Number,2) # output : 5.36
Example_2 :
print(round(5.53627894,2)) # output : 5.53
Great! The format method was new to me.
20:10
import math
def circle_stats(radius):
area = math.pi * radius * radius
circumference = 2 * math.pi * radius
return area, circumference
a, c = circle_stats(3)
print(f"Area: {a:.3f}, Circumference: {c:.3f}")
Thanks for such a simplistic, professional and in-depth content
for question 6(26:06), I used this:
cube = lambda user_in: user_in ** 3
user_in = float(input('Input a number for cube'))
print(cube(user_in))
Yr 900 views h fir bhi 400 comment kyu nhi hai😢 support kro yr sab chai aur code ko
my mind is just tuned with all your words, they just directly print into my mind i just simply run those without any errors , i think you have hacked my mind....grate full to u sir
thank you sir. I came to know about yeild for the first time. One application of args is in shoping cart.
Sab mil kar appreciate kro yr sir ki dedication ko quality content ke liye..😊
00:00
Introduction to Python Functions and Syntax
05:54
Understanding Python Function Parameters and Return Values
11:47
Understanding Function Execution in Python
17:41
Understanding Function Parameters and Return Values in Python
23:33
Understanding Python Functions and Syntax
29:30
Handling Multiple Arguments in Python Functions
35:24
Understanding the Syntax of Print Function in Python
41:17
Understanding Python Generator Functions and Yield Concept
47:12
Understanding the Implementation of Yield and Recursion in Python
53:06
Understanding Recursion and Factorial Calculation
53:06Recursion involves calling a function from within itself
54:11Factorial calculation using recursion involves breaking down the problem and solving it step by step
56:04Focus on developing a good exit strategy when working with recursion
20:11 import math
def circlestat(radius):
area = math.pi * radius **2
circumference = 2* math.pi *radius
return area ,circumference
a,b = circlestat(6)
a= round(a,3)
b=round(b,3)
print("area: ",a , "circumference",b)
round() is used to take those values upto 2 or 3 decimal places only
We can use the f-strings functionality. For example, if we want precision up-to 2 digits, then we can type: -
print(f"Area : {a:.2f} Circumference: {c:.2f}")
became a fan watching your video on 'tech for 2025'...im a pseudo python developer from bangladesh, your new follower. best wishes, bro.
We do use round method for getting precise values. e.g., round(number, 2) for getting precision upto 2 digits.
Super Guru ji.....Very insightful.....You are a great teacher Hitesh sir ji....keep up the great work......Respect from Bangalore...
Now I'm feeling that I'm diving into the internal working of python. The way he explains every topics that is phenomenal. I'm regularly waiting for his python series videos. Thanks sir for making this wonderful series.
00:03 Introduction to functions in Python
02:16 Learning functions in Python with confidence
06:06 Variables and function parameters in Python
08:07 Using the return keyword to output a result from a function in Python
12:05 Polymorphism in Python functions
14:17 Creating functions to return multiple values in Python
18:22 Returning multiple values from a function in Python
20:22 Creating and handling functions in Python.
24:13 Creating a function to compute the cube of a number
25:53 Understanding function definitions in Python
29:25 Using Python's special parameters to handle input values efficiently.
31:21 Printing and investigating errors in Python functions
34:53 Functions in Python and their usage with keyword arguments
36:52 Understanding function definitions and arguments in Python
40:42 Using formatting strings to print values in Python functions
42:33 Creating a function to generate even numbers with a limit in Python.
46:37 Understanding function implementation in Python
48:38 Functions in Python use yield to produce a sequence of values
52:16 Creating a function to calculate factorial and understanding recursion
54:18 Recursive approach to calculate factorial in Python
57:56 Learned the key concepts of functions in Python
Crafted by Merlin AI.
Great video, yr 2 din se kuch smj nhi aa rha tha ise dekh k maza aa gya
kahan gayi janta , abhi 10 din aur aaye gii videos. Comments target priority
your teaching style is relax and pressure free
The way he explained Yield keyword is beautiful !! LoveFromINDORE
this is my favorite youtube channel , nice teaching sir ji
Best Video Ever on Functions
really a good teaching technique sir
❤ the way of teaching
Direct jump on hands on approach
Amazing content sir..❤..if you plan to make another lecture, plz dive in little more in Recursion and Yield concept .
import math
def circle_stats(radius):
area = math.pi * radius ** 2
circumference = 2 * math.pi * radius
return area, circumference
a, c = circle_stats(3)
print("Area", round(a), "Circumference", round(c))
Syntax = round(number, digits)
51:00 amazing explanation sir👏
I have never ever seen this kind of teaching 🙏,Thank you sir for you your efforts for us.
thank you so much for teaching us in depth, lots of love from Jharkhand
Exited for the series that will based on python, Please start with Django if possible, It will be next level in your style and explanation in depth ♥
yup. django from his side will be amazing
20:26 round to 2 decimal :- round(a,2)
Output: 28.27
reached functions!🥳 was left behind a few videos for a while, but covering it up!!!!🤧
Please yr sab mil kr appreciate kro channel ko chai aur code 😊❤
Yaha behind the scenes sikhne ko milta hai
20:20
Round method can be used to get result with n decimal places.
print "Area:", round(a,n), "Circumference:", round(c,n))
Thank you for this video, never learned in this simplified way
Awsome Guru ji.......Pls make more videos on python DSA focused on Data Science and Machine Learning........Respect from Bangalore...
def sums(*arg):
total =0
for i in arg:
total+=i
print(total)
sums(1200.50,
340.75,
560.00,
980.25,
2150.00)
I love your teaching hitesh sir !!! I connect with you in coding
Thank you sir for building this things easily
Thank you so much sir for ❤ I love your way to teach and enjoying ever vedio of Chay and code .thank you❤
This series YIELDS in depth knowledge.😁😁
Now "yield" is very clear to me ❤
Such in depth explanation is astonishing in free courses! 🙌
sir aapko killvish ko bhi add karna chahiye tha main villan ki tor pe
wese is tarike se python ke function ko sikh kar ke maza hi aa gaya
love from mumbai sir ji ❤❤
for Area and Circumference exercise, we can use Round of method to get result printed by 2 or 3 digits.
the best channel to learn Python. need flask tutorial too Sir.
Thank you so much sir , we really love this series also. ❤❤
One word-wow! Truly amazing!
Every topic is explained very neatly and clearly.
Simply by Using round()
function
it takes up to 2 parameters
import math
def calc(radius):
area = math.pi * (radius **radius)
c = 2*math.pi*radius
return round(area, 2), round(c, 2)
areaOut ,c = calc (5)
print(f"Area : {areaOut}
Circumference : {c}")
Amazing explanation sir ❤
Awesome lessons!!! Very well explained
Thank you Sir, You really made thing so easy to understand.
05) USER INPUT
def greet(name="USER"):
return "HELLO ," + name + " !"
n1 = str(input("ENTER YOUR NAME : "))
if len(n1) >0:
print(greet(n1))
else:
print(greet())
very nice recursive problem solving approch
# Function Returning Multiple values
# Problem : Create a function that returns both the area and circumference of a circle given its radius.
import math
def circle_stats(radius):
area = math.pi * radius ** 2
circumference = 2 * math.pi * radius
return area , circumference
a , c = circle_stats (3)
print("Area: ", round(a,2), "Circumference: ",round(c,2)) #Assignment
Very nicely explaining sir...
Problem 4:
import math
def calc_circle(radius):
area = math.pi * radius ** 2
circumference = 2 * math.pi * radius
return area, circumference
a, c = calc_circle(3)
print("Area: ", round(a, 2), "Circumference: ", round(c, 2))
"This series is a hidden treasure for programmers."
import math
def circle_calculate(radius):
area = math.pi *radius**2
circumference = 2 * math.pi * radius
return area, circumference
a,c = circle_calculate(3)
print("Area:",round(a,2), "Circumference:",round(c,2))
19:51
print(f"Area: {a:.2f}
Circumference: {round(c,2)}")
def radius(r):
area = 3.14* r*r
circumference = 2*3.14*r
return area, circumference
area, circumference = radius(5)
formatted = "{:.3f}".format(area)
formatted = "{:.3f}".format(circumference)
print(formatted)
# print(radius(5))
people who didn't understood how actually the yield program in solution 9 works, read below to understand....
Function Definition:
The program starts by defining a generator function named even_gen.
This function takes one parameter limit, which represents the upper limit of the range of even numbers to generate.
Inside the function, a for loop is used to iterate over a range starting from 2 (the first even number) up to and including the specified limit, incrementing by 2 in each step.
Within the loop, the yield keyword is used to yield (or generate) each even number.
Generator Function Execution:
When the even_gen function is called with an argument (e.g., even_gen(10)), it doesn't start executing immediately. Instead, it returns a generator object.
The generator object represents an iterable sequence of even numbers based on the specified limit.
Iteration using a for loop:
The generator object returned by even_gen is iterated over using a for loop.
In each iteration, the for loop retrieves the next value from the generator using the next() function implicitly.
The next() function resumes the execution of the generator function until the next yield statement is encountered.
The value yielded by the yield statement (an even number) is assigned to the variable num, and the loop body is executed.
Printing Even Numbers:
Inside the loop body, each even number generated by the even_gen function is printed using the print statement.
In this case, the even numbers from 2 to 10 are printed, as the limit argument passed to even_gen is 10.
End of Iteration:
The for loop continues iterating until there are no more values to yield from the generator.
Once all the even numbers within the specified range are yielded and processed, the loop terminates.
Program Termination:
After the loop finishes execution, the program ends as there is no more code to execute.
In summary, the program defines a generator function that yields even numbers within a specified range, and then iterates over the generated numbers, printing each one. This approach efficiently generates and processes even numbers one at a time, conserving memory compared to storing all even numbers in a list.
Sir whatever you will to teach I'll learn all of it
really loved this way of learning...
Thank you soooooo much sir!!
this is a very important video of the series, DO NOT SKIP
Love this way of solving problem learning ❤
best creater of youtube
import math
def circle_stats(radius):
circle = math.pi * radius ** 2
circumference = 2 * math.pi * radius
return round(circle,2), round(circumference,2)
radius = int(input("Enter radius: "))
circle, circumference = circle_stats(radius)
print("Area: ",circle ,"&" , "Circumference: ",circumference)
def area_circumference(a):
area = (3.14)*(a)*(a)
circumference =2*3.14*(a)
print("area=",area)
print("circumference=",circumference)
a = float(input("enter the radius:"))
(area_circumference(a))
Thank you Sir for your efforts
Good way of teaching 👍
Explanation of Recursive function with pen & diagram sir 😊
Thank you so much sir ❤❤
print(“area:”,round(a,2),”circumference”,round(b,2))
20:23
# Use string formatting to round to 2 decimal places
print("Area: {:.2f}, Circumference: {:.2f}".format(a, c))
# Use the round() function to round to 2 decimal places
print("Area:", round(a, 2), "Circumference:", round(c, 2))
def square(a):
print(a*a)
a =int(input("enter the number:"))
square(a)
28:21
cube = lambda x : x**3
a = cube(4)
print(a)
print(cube(3))
it seems we can lambda like as def
you explained very well, thank you sir
Loved it!!!! Thank you so muchhh💞
Perfect Teaching 👌
THANK YOU SIR FOR THIS AMAZING SERIES 🥳🥳
commenting just because for your hard work
import math
def cs(r):
area = math.pi * r ** r
circumference = 2 * math.pi * r
return area, circumference
a, c = cs(3)
# print(f"area: {round(a, 2)} Circumference: {round(c, 2)}")
print(f"area: {a:.2f} Circumference: {c:.2f}")
solution:-
def radius(r1):
area=math.pi*r1**2
circumference=2*math.pi*r1
return area, circumference
a,c=radius(4)
print(f"area={round(a,2)}
circumference={round(c,2)}")
20:10 we can use round() method :)