Mapa mental
Python Functions
Contenido del mapa
Python Functions
Variable Function Arguments
- Python Default Arguments
- Any number of arguments in a function can have a default value. But once we have a default argument, all the arguments to its right must also have default values.
- def greet(name, msg="Good morning!"): print("Hello", name + ', ' + msg) greet("Kate") greet("Bruce", "How do you do?")
- Python Keyword Arguments
- Python allows functions to be called using keyword arguments. When we call functions in this way, the order (position) of the arguments can be changed. Following calls to the above function are all valid and produce the same result.
- greet(msg = "How do you do?",name = "Bruce")
- Python Arbitrary Arguments
- Sometimes, we do not know in advance the number of arguments that will be passed into a function. Python allows us to handle this kind of situation through function calls with an arbitrary number of arguments. In the function definition, we use an asterisk (*) before the parameter name to denote this kind of argument. Here is an example.
- def greet(*names): print("Hello", name) greet("Monica", "Luke", "Steve", "John") greet("Monica", "Luke", "Steve", "John")
- Python Default Arguments
Información
- Descripción
- Mapa Mental sobre Python Functions, creado por Sachin Mishra el 24/04/2020.
- Creado por
- Sachin Mishra
- Visitas
- 0
- Valoración