Functions

Run the program using the â–¶ button.

Notice the line that says Program started! near the top of the output pane. The program generated that output first, and after that it generated the other output which is the graph. The Program started! output generated by the print function in line 5.

👉Functions are code blocks that accomplish a specific task. Each function has a name. In our case, the name of the function is print. The code block that defines the print function is written somewhere inside the embedded interpreter that interprets and executes the Python code, but as programmers we don't need to see that code. All we are interested about is to use that print function. And the way we use the print function is by writing print followed by open-close parenthesis and inside the parenthesis we write the text we want to print out enclosed in double quotes. The "Program started!" part inside the parenthesis is referred to as the function argument.

Try experimenting with the print function. Here are some things you can try:

  • Change the argument of the print function from "Program started!" to something else and press the â–¶ button to see the new output. Do not forget the double quotes!
  • Write another print function in a new line under the existing print function and run again to see the output. You will see two lines in the output this time.

💡Tip: If you mess up the code above, reload the webpage with CTRL + R or CMD + R to reset the code.

Next Lecture
Recommended Course

Python Mega Course: Learn Python in 60 Days, Build 20 Apps
Learn Python on Udemy completely in 60 days or less by building 20 real-world applications from web development to data science.