Different Ways To Use Python Print Function – POFTUT

Different Ways To Use Python Print Function

Python is very expressive language which provides a lot of different output types and extensions. Printf is one of the most used function to print output. In this tutorial we will look different usage types of printf

Print String Value

This is the simplest usage form of the printf function. We will create a variable named a which holds string "Hi Poftut" . We will print this string by providing in to print function.

We will create a python source file named mytest.py and write download code and run it.

Print String Value

Print String Value

Use Variables

We can use python variables in print function in string definition. We will  We will provide the variable names in curly braces like below.

The output will the value of a appended to the print function string. We provide the value with format function into print function. The output will be like below.

LEARN MORE  Python, How To Print Without Newline or Space?

Put Spaces and Tabs

While using print function formatting is important. We can format the output by using format specifiers those are similar to the variable specifiers.

We will get following output where the variable a is spaces 20 character.

echo '

Print Dictionary, Tuple etc.

We generally use different type of data structures in our applications. We can easily print these type of key and values pairs with print .

Print Dictionary, Tuple etc.

Print Dictionary, Tuple etc.

Leave a Reply

Your email address will not be published. Required fields are marked *