In Python, the print() function is used to display output to the screen. You can use it to print text, variables, or any other information you want to see while running your program.
Here’s a simple example:
print("Hello, World!")
You can also print variables:
output = "Hello, World!"
print(output)
print()
function is capable to print multiple variables at one time.
variable1 = "We "
variable2 = "are "
variable3 = "Python Lover"
print(variable1, variable2, variable3)
Notice the space characters after “we ” and “are “, without space character the result would be “WearePython Lover
For numbers +
operator are uses for mathematical operator
variable1 = 5
variable2 = 6
print(variable1 + variable2)
Python will give you an error when try to combine String
and Number
with +
operator
variable1 = 5
variable2 = "Apple"
print(variable1 + variable2)
The Best way to combine and string
and integer
is seperate it with comma ( , )
:
variable1 = 5
variable2 = "Apple"
print(variable1, variable2)
To combine a string and an integer in the print()
function in Python, you can use the str()
function to convert the integer to a string, and then concatenate it with the string using the +
operator. Here’s an example:
my_string = "The value is "
my_integer = 42
print(my_string + str(my_integer))