FreeKB - Python (Scripting) Create a subroutine or function (def)
Python (Scripting) - Create a subroutine or function (def)

A subroutine is a collection of markup that can be used in our Python script. For example, let's say you want to print a long line of text many times in your script. You can place the long line of text inside of a subroutine.

def myText():
  print("This is a very long line of text.")
  print("This text is going to be used many times.")
  print("Placing this text over and over in our script is going to make our script look messy.")
  print("Let's be smart and put the text in a subroutine called myText.")


Since our subroutine is called "myText" in this example, the subroutine can be used simply by placing "myText();" in the Python script.



Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter 44a97 in the box below so that we can be sure you are a human.


Web design by yours truely - me, myself, and I   |   |