print function in python
print function is used to print a value, sentence and variable etc. Let's look at some of the examples.
print('Hello')
print('This is the statement that has to be printed')
output: Hello This is the statement that has to be printed
var1 = 10 #initializing a variable
print(var1) #displaying the value stored in car1
var2 = 'M' #initializing a variable
print(var2) #displaying the value stored in var2
var3 = True #initializing a variable
print(var3) #displaying the value stored in var3
output: 10 M True
Other important operations using print function
Print a variable and it’s value together.
blog = 'codicious.com'
print('the name of the blog is', blog)
output: the name of the blog is codicious.com
var1 = 10
var2 = 20
sum = var1 + var2
print('the sum', var1, '+', var2, 'is', sum)
output: the sum 10 + 20 is 30
print function using format command
blog = 'codicious.com'
print(f'the blog name is {blog}')
output: the blog name is codicious.com
Format command is used in print function, where in the key 'f' which is denoted as format and is used before the quotes. With the help of format command we can use the variable names directly within the flower brackets.
var2 = 10
var4 = 20
sum = var2 + var4
print(f"the sum {var2} + {var4} is {sum}")
output: The sum 10 + 20 is 30Read FullRead Full