newtum

Our Social Network

PYTHON PRINT STATEMENTS: UNDERSTANDING UNFORMATTED OUTPUT

Python Print Statements: Understanding Unformatted Output

Python is simple and powerful — but only if you practice. If you're just starting, it’s important to write code after every session. Practicing early will make it easier to grasp the more advanced concepts we'll cover in future lessons. In this post, we'll explore unformatted output using print statements and see how to concatenate text and variables in Python.

What Is Unformatted Output in Python?

The print() function in Python is used to display information on the screen. Whatever you write inside the print() statement is printed as it is. When you print a mix of text and variable values without using specific formatting methods, it’s called unformatted output.

Let’s understand this with an example. Suppose we want to display the population of a country.

We’ll declare two variables:

  • country = "India"
  • population = 130

Using the print() function, we can write:

python
CopyEdit

print("Population of", country, "is", population, "crores")

This combines both string and variable values using commas. The commas act as concatenation operators, meaning they join different elements together for display.

But if we use the + symbol to concatenate:

python CopyEdit

print("Population of " + country + " is " + population + " crores")

This will raise an error because population is an integer, and you can’t concatenate a string with an integer directly using +

To fix this, we need to convert the integer to a string using the str() function:

python CopyEdit

print("Population of " + country + " is " + str(population) + " crores")

This process is called typecasting or type conversion.

Sample Python Code

1country = "India"
2population = 130
3
4# Using commas
5print("Population of", country, "is", population, "crores")
6
7# Using + with typecasting
8print("Population of " + country + " is " + str(population) + " crores")

Code Explanation

  • country and population store the required data.
  • The first print() uses commas to concatenate string and variable values.
  • The second print() uses + symbols, but the population value is converted using str().
  • str() is used for typecasting an integer to a string so it can be concatenated.
  • Both methods produce the same output but handle data differently.

Output

Population of India is 130 crores
Population of India is 130 crores

Watch the Full Video

Check out our YouTube session for a full walkthrough of this topic and a demo of the code: Watch on YouTube

Final Words

Today you learned about unformatted output and how to concatenate strings and variables using both commas and plus signs. Practice well using these examples and be ready for our next session, where we’ll cover formatted output in Python.

More Articles

Ready to Explore the Future of Technology?

Unlock the tools and insights you need to thrive on social media with Newtum. Join our community for expert tips, trending strategies, and resources that empower you to stand out and succeed.

Newtum

Newtum is an emerging online academy offering a wide range of high-end technical courses for people of all ages. We offer courses based on the latest demands and future of the IT industry.

© Newtum, Inc. All Rights Reserved.