Function with Return Value - Introduction to Python: Absolute Beginner Module 2 Video 4

Veröffentlicht am: 06 August 2021
auf dem Kanal: Book Simplifiers
59
1

Concept: Function with Return Value
Calling a function with a return value
type() returns an object type
type() can be called with a float the return value can be stored in a variable
object_type = type(2.33)
creating a function with a return value
return keyword in a function returns a value after exiting the function
def msg_double(phrase):
double = phrase + " " + phrase
return double
Example
review and run the code

Message double returns the string Argument doubled
def msg_double(phrase):
double = phrase + " " + phrase
return double

save return value in variable
msg_2x = msg_double("let's go")
print(msg_2x)
example of functions with return values used in functions
def msg_double(phrase):
double = phrase + " " + phrase
return double

prints the returned object
print(msg_double("Save Now!"))

echo the type of the returned object
type(msg_double("Save Now!"))
Task 1
Doctor: a function that adds the "Doctor" title to a name
Define function make_doctor() that takes a parameter name
get user input for variable full_name
call the function using full_name as argument
print the return value
create and call make_doctor() with full_name argument from user input - then print the return value


Auf dieser Seite können Sie das Online-Video Function with Return Value - Introduction to Python: Absolute Beginner Module 2 Video 4 mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Book Simplifiers 06 August 2021 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 59 Mal angesehen und es wurde von 1 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!