I'm reach level 4 and i have problems in defines function? i can't understand it very will☹️ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

I'm reach level 4 and i have problems in defines function? i can't understand it very will☹️

3rd May 2018, 5:37 AM
Hawaa Basheer Ali Elamin
Hawaa Basheer Ali Elamin - avatar
2 Answers
+ 3
Congratulations on your new level Hawaa Basher Ali ! Coming back to your problem, " ' Defining a function ' Here’s a simple function named greet_user() that prints a greeting: (1) def greet_user(): (2) """Display a simple greeting.""" (3) print("Hello!") (4) greet_user() This example shows the simplest structure of a function. The line at (1) uses the keyword def to inform Python that you’re defining a function. This is the function definition, which tells Python the name of the function and, if applicable, what kind of information the function needs to do its job. The parentheses hold that information. In this case, the name of the function is greet_user(), and it needs no information to do its job, so its parentheses are empty. (Even so, the parentheses are required.) Finally, the definition ends in a colon. Any indented lines that follow def greet_user(): make up the body of the function. The text at (2) is a comment called a docstring, which describes what the function does. Docstrings are enclosed in triple quotes, which Python looks for when it generates documentation for the functions in your programs. The line print("Hello!") (3) is the only line of actual code in the body of this function, so greet_user() has just one job: print("Hello!"). When you want to use this function, you call it. A function call tells Python to execute the code in the function. To call a function, you write the name of the function, followed by any necessary information in parentheses, as shown at (4). Because no information is needed here, calling our function is as simple as entering greet_user(). As expected, it prints Hello!: Hello! " #Excerpts from a book
3rd May 2018, 6:38 AM
Rahul George
Rahul George - avatar
+ 3
thank you a lot 🤗 😍 😍
8th May 2018, 2:40 PM
Hawaa Basheer Ali Elamin
Hawaa Basheer Ali Elamin - avatar