Python | Printing different values (integer, float, string, Boolean)

Python example to print different values: Here, we are going to learn how can we print different types of values using print() method in Python? By Pankaj Singh Last updated : April 08, 2023

Printing integer, float, string and Boolean using print()

In the given example, we are printing different values like integer, float, string, and Boolean using print() method in Python.

# printing integer value 
print(12)
# printing float value 
print(12.56)
# printing string value 
print("Hello")
# printing boolean value 
print(True)

Output

12
12.56
Hello
True

Arithmetic operations inside the print() on values

In this example, we are performing some of the arithmetic operations inside the print() method using the arithmetic operators.

# adding and printing integer value 
print(12+30)
# adding and printing float value 
print(12.56+12.45)
# adding and printing string value 
print("Hello"+"World")
# adding and printing boolean value 
print(True+False)

Output

42
25.009999999999998
HelloWorld
1

Printing variables of different types inside the print()

# variable with integer value
a=12
# variable with float value
b=12.56
# variable with string value
c="Hello"
# variable with Boolean value
d=True

# printing all variables 
print(a)
print(b)
print(c)
print(d)

Output

12
12.56
Hello
True

Printing different types of variables along with the messages

# variable with integer value
a=12
# variable with float value
b=12.56
# variable with string value
c="Hello"
# variable with Boolean value
d=True

# printing values with messages 
print("Integer\t:",a)
print("Float\t:",b)
print("String\t:",c)
print("Boolean\t:",d)

Output

Integer : 12
Float   : 12.56
String  : Hello
Boolean : True

Printing different variables with messages and converting them to string using str()

Here, we are converting the different types of values into the string inside the print() method using the str() method. [Read more about the Python string methods)

# variable with integer value
a=12
# variable with float value
b=12.56
# variable with string value
c="Hello"
# variable with Boolean value
d=True

# printing values with messages 
print("Integer\t:"+str(a))
print("Float\t:"+str(b))
print("String\t:"+str(c))
print("Boolean\t:"+str(d))

Output

Integer :12
Float   :12.56
String  :Hello
Boolean :True

Python Basic Programs »

Related Programs

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.