filmov
tv
Python Quiz 13: Can You Guess the Output of this Python Code? | Function Quiz | Python For Beginners
![preview_player](https://i.ytimg.com/vi/k4KVCxU5oMg/maxresdefault.jpg)
Показать описание
In this Python code, we have defined a function called "add" that takes in two arguments, "a" and "b", and an arbitrary number of additional arguments which are collected into a tuple called "parm" using the syntax "*parm".
def add(a,b,*parm):
total = 0
print(a+b)
for n in parm:
total += n
return total
print(add(1, 2))
The function first prints the sum of "a" and "b" using the "+" operator, and then iterates over the "parm" tuple using a "for" loop, adding up all the values in the tuple to a variable called "total". The function then returns the value of "total".
In the main body of the code, we call the "add" function with the arguments 1 and 2, and since there are no additional arguments provided, the "parm" tuple is empty. The function therefore only prints the sum of 1 and 2 (which is 3) and returns 0, since there are no values in "parm" to add up.
The final output of the code, when executed, will be:
3
0
If you enjoyed this video, please give it a thumbs up 👍and leave a comment 💬 below. Don't forget to subscribe 🔔to my channel for more Python tutorials like this one.
YouTube Playlists:
You can also follow me on:
Thanks for watching! 🙏**
#codingshorts #coding #pythonprogramming #codingshortvideo #python #pythonbasics #yasirbhutta #codinglife #pythontutorial #python3
def add(a,b,*parm):
total = 0
print(a+b)
for n in parm:
total += n
return total
print(add(1, 2))
The function first prints the sum of "a" and "b" using the "+" operator, and then iterates over the "parm" tuple using a "for" loop, adding up all the values in the tuple to a variable called "total". The function then returns the value of "total".
In the main body of the code, we call the "add" function with the arguments 1 and 2, and since there are no additional arguments provided, the "parm" tuple is empty. The function therefore only prints the sum of 1 and 2 (which is 3) and returns 0, since there are no values in "parm" to add up.
The final output of the code, when executed, will be:
3
0
If you enjoyed this video, please give it a thumbs up 👍and leave a comment 💬 below. Don't forget to subscribe 🔔to my channel for more Python tutorials like this one.
YouTube Playlists:
You can also follow me on:
Thanks for watching! 🙏**
#codingshorts #coding #pythonprogramming #codingshortvideo #python #pythonbasics #yasirbhutta #codinglife #pythontutorial #python3