Concept: Function Parameters
Functions that have Parameters
print() and type() are examples of built-in functions that have Parameters defined
type() has a parameter for a Python Object and sends back the type of the object
an Argument is a value given for a parameter when calling a function
type is called providing an Argument - in this case the string "Hello"
type("Hello")
Defining Function Parameters
Parameters are defined inside of the parenthesis as part of a function def statement
Parameters are typically copies of objects that are available for use in function code
def say_this(phrase):
print(phrase)
Function can have default Arguments
Default Arguments are used if no argument is supplied
Default arguments are assigned when creating the parameter list
def say_this(phrase = "Hi"):
print(phrase)
Example
yell_this() yells the string Argument provided
def yell_this(phrase):
print(phrase.upper() + "!")
call function with a string
yell_this("It is time to save the notebook")
use a default argument
def say_this(phrase = "Hi"):
print(phrase)
say_this()
say_this("Bye")
Task 3
Define yell_this() and call with variable argument
define variable words_to_yell as a string gathered from user input()
Call yell_this() with words_to_yell as argument
get user input() for the string words_to_yell
[ ] define yell_this()
[ ] get user input in variable words_to_yell
[ ] call yell_this function with words_to_yell as argument
Sur cette page du site, vous pouvez voir la vidéo en ligne function parameters - Introduction to Python: Absolute Beginner Module 2 Video 3 durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur Book Simplifiers 06 août 2021, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 79 fois et il a aimé 2 téléspectateurs. Bon visionnage!