About
Kodeclik is an online coding academy for kids and teens to learn real world programming. Kids are introduced to coding in a fun and exciting way and are challeged to higher levels with engaging, high quality content.
Popular Classes
Scratch Coding
Minecraft Coding
TinkerCAD
Roblox Studio
Python for Kids
Javascript for Kids
Pre-Algebra
Geometry for Kids
Copyright @ Kodeclik 2025. All rights reserved.
Python’s print() is a versatile function that provides various options to format and style the output from your programs.
The first thing to note about Python’s print() is that it is a function which means you need to pass it arguments. For instance:
This yields the output:
If we do:
We get:
Note that the second print() command prints its output on a new line. Calling print() without any arguments yields a blank line. For instance, the following segment of code:
We can create a composite statement by printing a combination of strings using the string concatenation (+) operator.
This yields the output:
Note that we have included extra spaces around “is” and before “years old” in order to obtain the formatted string. (See also our detailed blogpost on the Python concatenate operator.)
Note carefully that the variable year has been defined as a string. If you try it like this:
You will get the error:
The reason for the error is that the concatenation operator requires strings on both sides of the operation. There are two ways to fix this. One is to convert the integer into a string using the str() function.
Another is to keep the year as integer and instead use print() as follows:
This will yield the output:
Note that there are extra spaces included if we use year as a separate argument in the print() function. We should therefore update the program as:
When you use the multiple argument version of print() there are additional options available. For instance, you can do:
This gives:
The sep argument denotes the separator. In this case we are telling print() to use the string “--” as a separator (instead of the default single space). So if you wanted to mimic the effect of the “+” operator, you make sep to be an empty string.
This gives:
Using separators is particularly useful if you are printing your output to a file that will later be read by a program like Excel so that when importing the file you can specify the separator.
Just like the separator argument that specifies what should be printed *in between* the elements, there is an argument to specify what should be printed at the end. Recall that every print() statement starts on a newline. From this you can infer that the default end character is a newline. We can change it like so:
This gives:
Here is a place where this is useful. Suppose we would like to print all the months in a year with commas between them. One way to do it would be:
Note that, inside the for loop, we are printing all months except the last with an empty string as a separator (between the month and the comma), and then a space as an end character (before the next month is printed in the next print() statement inside the loop). Recall that the index "-1" has a special meaning in Python.
Finally, we print the last month with a period at the end. This program uses all the elements we have discussed so far.
For more interesting content on Python printing, learn how to print special characters using the Python chr() function. Also checkout our blogpost on printing lists in Python.
Interested in more things Python? See our blogpost on Python's enumerate() capability, how to print to stderr, and how to read a text file in Python. Also learn all about computing square roots in Python and master recursion in Python!
Want to learn Python with us? Sign up for 1:1 or small group classes.
print(“Hello, how are you?”)
Hello, how are you?
print("Hello, how are you?")
print("I am ok")
Hello, how are you?
I am ok
print("Hello, how are you?")
print()
print("I am ok")
Hello, how are you?
I am ok
name = "John"
year = "10"
print(name + " is " + year + " years old.")
John is 10 years old.
name = "John"
year = 10
print(name + " is " + year + " years old.")
Traceback (most recent call last):
File "main.py", line 3, in <module>
print(name + " is " + year + " years old.")
TypeError: can only concatenate str (not "int") to str
name = "John"
year = 10
print(name + " is " + str(year) + " years old.")
name = "John"
year = 10
print(name + " is ", year, " years old.")
John is 10 years old.
name = "John"
year = 10
print(name + " is", year, "years old.")
student1 = "John"
student2 = "Kathy"
student3 = "Ryan"
print(student1,student2,student3,sep="--")
John--Kathy--Ryan
student1 = "John"
student2 = "Kathy"
student3 = "Ryan"
print(student1,student2,student3,sep="")
JohnKathyRyan
print("This will be on a line by itself")
print("This is the second line",end='')
print("This is also the second line")
This will be on a line by itself
This is the second lineThis is also the second line
months = ['January','February','March','April','May','June',
'July','August','Sep','October','November','December']
for i in months[:-1]:
print(i,',',sep='',end=' ')
print(months[-1] + '.')