🌐
W3Schools
w3schools.com › python › python_functions.asp
Python Functions
Python Examples Python Compiler ... Python Bootcamp Python Certificate Python Training ... A function is a block of code which only runs when it is called....
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-functions
Python Functions - GeeksforGeeks
Python Functions are a block of statements that does a specific task.
Published   3 weeks ago
🌐
Programiz
programiz.com › python-programming › function
Python Functions (With Examples)
Become a certified Python programmer. Try Programiz PRO! ... A function is a block of code that performs a specific task.
🌐
Codecademy
codecademy.com › learn › flask-introduction-to-python › modules › learn-python3-functions › cheatsheet
Introduction to Python: Functions Cheatsheet | Codecademy
A function can be called by writing the name of it, followed by parentheses. For example, the code provided would call the doHomework() method. ... Parameters in python are variables — placeholders for the actual values the function needs.
🌐
Learn Python
learnpython.org › en › Functions
Functions - Learn Python - Free Interactive Python Tutorial
Where a block line is more Python ... "for", and "while". Functions in python are defined using the block keyword "def", followed with the function's name as the block's name....
🌐
Python documentation
docs.python.org › 3 › library › functions.html
Built-in Functions — Python 3.14.4 documentation
February 27, 2026 - The Python interpreter has a number of functions and types built into it that are always available. They are listed here in alphabetical order.,,,, Built-in Functions,,, A, abs(), aiter(), all(), a...
🌐
freeCodeCamp
freecodecamp.org › news › python-functions-define-and-call-a-function
Python Functions – How to Define and Call a Function
March 16, 2022 - In programming, a function is a reusable block of code that executes a certain functionality when it is called. Functions are integral parts of every programming language because they help make your code more modular and reusable.
🌐
Tutorialspoint
tutorialspoint.com › python › python_functions.htm
Python - Functions
A Python function is a block of organized, reusable code that is used to perform a single, related action. Functions provide better modularity for your application and a high degree of code reusing.
🌐
Real Python
realpython.com › defining-your-own-python-function
Defining Your Own Python Function – Real Python
June 11, 2025 - A Python function is a named block of code that performs specific tasks and can be reused in other parts of your code. Python has several built-in functions that are always available, and you can also create your own.
Find elsewhere
🌐
Stanford CS
cs.stanford.edu › people › nick › py › python-function.html
Python Functions
Another way to call a function is the object-oriented aka noun.verb style, like this: ... Here bit is Python data of some sort, and .move() is a function to run on that data. At its heart, this is still just a function call, but the data to work on is listed first, then a dot, then then the ...
🌐
DataCamp
datacamp.com › tutorial › functions-python-tutorial
Python Functions: How to Call & Write Functions | DataCamp
November 22, 2024 - In the previous sections, you have seen a lot of examples already of how you can call a function. Calling a function means that you execute the function that you have defined - either directly from the Python prompt or through another function (as you will see in the section “Nested Functions”).
🌐
Built In
builtin.com › software-engineering-perspectives › what-is-a-function-in-python
What Is a Function in Python? | Built In
A function in Python is a named section of code that takes an input, performs a specific operation and returns an output. Here's how functions work in Python.
🌐
DigitalOcean
digitalocean.com › community › tutorials › how-to-define-functions-in-python-3
How To Define Functions in Python 3 | DigitalOcean
August 20, 2021 - A function is a block of instructions that performs an action and, once defined, can be reused. Functions make code more modular, allowing you to use the same code over and over again. Python has a number of built-in functions that you may be familiar with, including:
🌐
Python Like You Mean It
pythonlikeyoumeanit.com › Module2_EssentialsOfPython › Functions.html
Basics of Functions — Python Like You Mean It
A function can be defined so that it accepts arguments, which are objects that are to be passed to the encapsulated code. Similar to if, else, and for, the def statement is reserved by the Python language to signify the definition of functions (and a few other things that we’ll cover later).
🌐
Compciv
compciv.org › guides › python › fundamentals › function-definitions
Function fundamentals in Python | Computational Methods in the Civic Sphere at Stanford University
If we think of variables as a sort-of label for data values, then think of functions as another kind of label, but for code that is meant to be called at a later time. Just as it is convenient to give a human-readable name – a.k.a. assigning a variable – to a complicated data object for later reference, it’s convenient ttindo give a label/nickname to a series of expressions that we intend to execute again. ... The token print is not a special Python keyword.
🌐
Simplilearn
simplilearn.com › home › resources › software development › your ultimate python tutorial for beginners › functions in python | definition, types and examples
Learn Functions in Python: Definition, Types, and Examples
June 9, 2025 - Learn about functions in Python: how they run when called, pass parameters, and return data. This guide helps you understand essential Python function concepts.
Address   5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
🌐
W3Schools
w3schools.com › python › python_ref_functions.asp
Python Built-in Functions
Python Functions Python Arguments Python *args / **kwargs Python Scope Python Decorators Python Lambda Python Recursion Python Generators Code Challenge Python Range
🌐
PYnative
pynative.com › home › python › python functions
Python Functions [Complete Guide] – PYnative
January 26, 2025 - Python function is a block of code defined with a name. Learn to create and use the function in detail. Use function argument effectively.
Top answer
1 of 4
24

what is the purpose of having the arg1, arg2 in the parenthesis next to it?

In this case, arg1 and arg2 are called arguments. Arguments allow functions to receive inputs it's expected to use in order to perform a task. The inputs are provided by the callers.

For example, in school math, you may've already seen things like z = f(x, y) where a function named f is defined as f(x, y) = x + y. This is the same concept in a programming language.

It also allows you do write more generic, flexible, and reusable code. For example, you don't have to write many different versions of a function to accomplish the same task with slightly different results, avoiding situations like add2(x, y) = x + y and add3(x, y, z) = x + y + z, and so on. You can simply do something like:

def sum(values):  # values is of type 'list'
    result = 0
    for value in values:
        result += value
    return result

And call it like this:

total = sum([1, 2, 3, 4, 5, 6, 7]) # a list of any length with numbers

Or like this:

total = sum([1, 2])

How many arguments a function needs will depend on what it needs to do and other factors.

Update

What confuses me is the print_two_again("Steve","testing") , what is this called and its purpose?

The line print_two_again("Steve","testing") is an invocation of the function (i.e. a function call). This causes the program to 'jump' into the body of the function named print_two_again and start executing the code in it.

The ("Steve","testing") part are the arguments being sent to the function as inputs. These are positional arguments, which basically means that they get "mapped" to the names arg1 and arg2 based on the order in which you've provided them when invoking the function.

For example, consider the function f(x, y) = x - y. If this function is called as z = f(3, 4) then the argument by the name of x will receive the value 3 and y will be 4, to return -1. If you reverse the arguments in the call, then you'd have x=4 and y=3 and it'd return 1 instead. The same is true of the arguments in the function you've provided.

This means that the order of the arguments in a function call is important.

The Python language, like many others, already has a set of built-in functionality. The function named print is an example of this. You can get a lot of information using the pydoc command (pydoc3 if you use Python3, which I'd recommend). For example, the command pydoc3 print produces the following documentation:

Help on built-in function print in module builtins:

print(...) print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)

Prints the values to a stream, or to sys.stdout by default.
Optional keyword arguments:
file:  a file-like object (stream); defaults to the current sys.stdout.
sep:   string inserted between values, default a space.
end:   string appended after the last value, default a newline.
flush: whether to forcibly flush the stream.

Note that this is documentation for Python3. Python2 documentation will be slightly different.

There's a direct correlation between your understanding of functions, as seen in your math courses in school, and functions as seen in a programming language. This is because math is part of the underlying foundation of computer science and programming languages, among others (e.g. analysis of algorithms).

2 of 4
7

what is the purpose of having the arg1, arg2 in the parenthesis next to it?

arg1 and arg2 are the names of the inputs and from there the function can use those inputs. In your case what your function does is to print them. Other functions can do other things with these arguments. But let's go step by step.

def print_two_again(arg1, arg2):
    print "arg1: %r, arg2: %r" % (arg1, arg2) 

In the first two lines starting with def, you define a function. It does something. In your case prints the two arguments it takes.

print_two_again("Steve","Testing")

On the third line what you actually do is to call that function. When you call that function you tell the function to pass "Steve" and "Testing" arguments to the function definition.

Above line is literally called a function call. Let's say you have a program and you want it to print two words. You need to define how you want it to be done. This is called function definition, where you define how things work. That's OK, but not enough. You would want to make it happen. So what you do is to execute that function. This is called a function call.

print_two_again("First","Call")
print_two_again("Second","Call")

In the above lines, what we did is to call the previously defined function two times but with different arguments.

Now let's look at the second line, which probably confuses you.

print "arg1: %r, arg2: %r" % (arg1, arg2) 

print is a built-in function in Python. What above line does here is to pass arg1 and arg2 arguments and print them with the format of "arg1: %r, arg2: %r"

🌐
Medium
jessica-miles.medium.com › writing-functions-in-python-a-beginners-guide-ed9182db959b
Writing Functions in Python— A Beginner’s Guide | by Jessica Miles | Medium
November 1, 2021 - Write the function definition using the format def function_name(): with empty parentheses (no parameters) to start with. Make sure to put a colon at the end. It’s conventional in Python to use all lower-case letters for function names, and underscores to separate words.