Python for non-programmers, lesson 12: Functions

preview_player
Показать описание
Learn how to define and use functions in Python — a key building block for writing better, more reusable code.

Want to teach the computer to do something new? You want to define a function. Not surprisingly defining functions is one of the most common things that programmers do. In this video, I introduce the idea of functions, how to define them, how to invoke them, and how to get results ("return values") back from them.

-----

Homework exercises for this lesson:

1. Write a function, maxnum, that takes a single argument, a list of numbers. It returns the largest number in that list. (Do not use the built-in max function to do this!)

2. Write a function, lastword, that takes a list of words. It returns the word in that list that occurs last, alphabetically.

3. Write a function, charcount, that takes a string and returns a dict. The dict’s keys will be all of the different characters that occur in the string, and its values will be the number of times that each character appeared.
Рекомендации по теме
Комментарии
Автор

🤔 What do you think about functions?

👇 Have questions about defining or calling? Drop them in the comments — I read them all.

📝 Want the course notebooks and practice materials?

ReuvenLerner
welcome to shbcf.ru