New: Practice Python, JavaScript & SQL with AI feedback — Try ActiveSkill free →

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.

Practice what you just learned

Solve Python exercises and get instant AI feedback on your solutions.

Try ActiveSkill for Free →
Next Lecture