print function in python

When the Python program needs to communicate with the user, We should use print function.

The communication can be,

Greeting the user

"welcome to c program"

Asking input from the user

"Enter your username/password" etc.

Syntax of print function

print('') #print function with single quote
print("") #print function with double quote 
print()   #print a value or value of a variable directly.

After printing the message the print function will automatically go to the next line.

To print a newline, we can use the print function without any message. i.e print()

Sample Program


#print function example

print(10)                        #printing value directly
print("Hello World")             #printing a message with double quotes
print('Enter two numbers')       #printing a message with single quotes

#We can easily add single and double quotes in python
print('Welcome to "log2base"')   #Adding double quotes
print("Welcome to 'log2base2'")   #Adding single quotes

Correct the below program

The below program has some syntax errors.

Correct the program by yourself and see the output.


#correct the below program

print(correct me)

print('correct me once again")

Topics You Might Like