Skip to Content

Python for Fintech Professionals: Print Function

The print() function in Python outputs text or variables to the console, allowing for easy display of information.
This is the fifth blog on Python for fintch professionals.

Print Function in Python

The print() function in Python outputs the specified arguments to the console. It can accept zero or multiple positional arguments.

For example:

a = "Hello"
b = "World!"
print(a, b)

This code will output: Hello World!

The print() function includes three keyword arguments with the following default values:

sep = " ": Specifies the separator between multiple arguments.

end = "\n": Specifies what to print at the end of the output.

Escape Characters

If a character needs to be included in a string that otherwise has a special meaning in Python, such as a single quote (') or a double quote ("), you can use a backslash (\) before the character. This backslash is called an escape character and pairs with another character to represent it literally. For example:

print('I didn\'t do that.')

This code would output: I didn't do that.

Additionally, "\n" is used to indicate a new line in the output, moving any subsequent text to the next line.

Note on Octal or Hexadecimal numbers

print() function automatically converts octal or hexadecimal numbers to integers when outputting them.


Share this post
Sign in to leave a comment
Python for Fintech Professionals: Functions
In Python, a function performs a specific task, can take input parameters and return a value.