Recording intelligenceAI-generated brief · check the source for context

Function Arguments in Python | Python Tutorial - Day #21

13:49 recording · EN · 1 speaker

Watch the original

Brief overview

A 100 Days of Code lesson on Python's four argument types and the return statement.

  1. Four argument types in Python functionsDefault, keyword, variable length and required arguments are the four kinds named in the lesson.
  2. Defaults fill in, keywords free the ordera = 9, b = 1 are used when nothing is passed, and b = 9, a = 21 works regardless of position.
  3. Star collects a tuple, double star a dictionary*numbers arrives as a tuple and **name as a dictionary, shown with type() printing class tuple and class dict.
Executive Summary AI
  • In this episode of 100 days of code the instructor takes up function arguments and the different ways they can be passed, including as a tuple and as a dictionary.
  • After building a simple average function that prints (a + b) / 2 and gives 5.0, he names the four argument types: default, keyword, variable length and required.
  • Giving a = 9 and b = 1 as defaults makes average() print 5, while calling it with 1 and 5 ignores the defaults and prints 3, and keyword arguments such as b = 9, a = 21 let the order be changed freely.
  • Rewriting the function as def average(*numbers) collects the arguments into a tuple, so average(5, 6) prints 5.5 and any count of numbers works because the sum is divided by len(numbers), while **name collects key = value pairs into a dictionary.
  • Finally he replaces the print with return, stores the result in c, and prints 4.75 for 5, 6, 7, 1, explaining that without a return the caller gets None and that only the first return executed is used.
Key Quote
“Default arguments, keyword arguments, variable length arguments”
— Speaker
Key Quote
“We can provide a default value while creating a function.”
— Speaker
Key Quote
“What you can do is change the order of the arguments.”
— Speaker