Python Coding Interview Questions: Functions in Python (+ Solution) - Python Tutorial for Beginners

preview_player
Показать описание
🎓 Welcome back to Digital Academy, the Complete Python Development Tutorial for Beginners, which will help you Learn Python from A to Z!

🖥️ Python Coding Interview Questions (Easy): Functions in Python (+ Solution)

In this brand NEW video, you will now discover a new way to write your own program, using Functions in Python. So be sure to stick around and watch until the end of this video, if you want to discover more and prepare for your Python Coding Interview session.

Suppose you want to SUM up ALL the items of a List passed as argument to your function, which contains the values 1, 2, 4, 6, 8 and 10 - then returns the computed result.

☞ How would you proceed? Please, Tell me in the comment what is your answer.

---

Let's declare a List with the following items: my_list = [1, 2, 4, 6, 8, 10].

Define your Function in Python: def sum_list(my_list) and add the following statements.

If you want to add ALL items from a List in Python, you have to Iterate using FOR Loop: for item in my_list, and add the current item to your local variable result: result += item.

Eventually, when no elements are left and you reached the end of your List, your Function will return the result.

That's it, You just wrote your own Function in Python, that iterates through a List, adds ALL items and returns the SUM of all of them.

my_list = [1, 2, 4, 6, 8, 10]

def sum_list(my_list):
result = 0
for item in my_list:
result += item
return result

sum_list(my_list)

Please, Tell me in the comment: What result did you get? Did you find another way to do the same thing? I will reply to everyone in the comments below, and help each other from this Python Community.

Let's play this video, stick around and watch until the end of this video! 👍🏻

- Digital Academy™ 🎓

***

☞ WATCH NEXT:

#Python #Tutorial #Beginners #Shorts

***

♡ Thanks for watching and supporting ♡
Please Subscribe. Hit the notification bell.
Like, Comment and Share.

***

♡ FOLLOW US ♡

♡ SUPPORT US ♡

***
Рекомендации по теме
Комментарии
Автор

Let’s prepare for your Python Interview Questions. Please, Tell me in the section comments below: What is your answer? 🤔

DigitalAcademyOnline
Автор

YOUR VIDEOS ARE SO GOOD OMG ITS SO GOOD ANIMATED!! ❤️

nichtmehramix