Python (Scripting) - Pass values into a function

If you are not familiar with functions, refer to Getting Started with functions in Python.


A function must be define before the function is called in the script. For example, let's say you call the "foo" function before the foo function is defined.


Hello "World"

def Hello(greeting):
  print greeting


This will return an error that looks something like this.

Traceback (most recent call last):
  File "/home/john.doe/", line 3, in <module>
NameError: name 'Hello' is not defined


In this example, values "Hello" and then "World" are passed into the Hello function.

The values passed into the Hello function are placed in the "greeting" variable.


def Hello(greeting):
  print greeting



Here is how you would pass two (or more) values into a function.


def Hello(one,two):
  print one
  print two

Hello("Hello", "World")


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 e03c1 in the box below so that we can be sure you are a human.


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