0

Define function

What are the best way to understand function and how to define them also how the function called with the input from user

6th Jan 2024, 2:19 AM
Sumit maurya
Sumit maurya - avatar
2 Answers
+ 4
The best way to understand function is to define your own function. To define a function, use the def keyword. Here is a simple function which is called with the user input. def greeting(someone): # it uses keyword def, and has an argument 'someone' inside the parentheses return "Hello, " + someone + "." # it uses keyword 'return' to return a string name = input("Please enter your name: ") #e.g. Sumit maurya print(greeting(name)) # it call the function greeting with an argument, and the returned string got printed # Hello, Sumit maurya. And it is a shortcut. print(greeting(input("Please enter your name: "))) All the steps are discussed in the introduction course "Making Your Own Function", "Function Arguments" and "Returning from Functions". You can re-read them anytime as you want.
6th Jan 2024, 3:35 AM
Wong Hei Ming
Wong Hei Ming - avatar
0
Thank you so much 😊
6th Jan 2024, 3:38 AM
Sumit maurya
Sumit maurya - avatar