Skip to content

input-output

Input

Python's input() function is used to take user input. By default, it returns the user input in form of a string.

name = input("Enter your name: ")
print("Hello,", name, "! Welcome!")

python <filename>.py

Enter your name: Ashe
Hello, Ashe ! Welcome!

Output

The print() function allows us to display text, variables and expressions on the console. In the below example, "Hello, World!" is a string literal enclosed within double quotes. When executed, this statement will output the text to the console.

print("Hello, World!")

python <filename>.py

Hello, World!

Printing Variables

s = "Bard"
print(s)

s = "Ashe"
age = 28
city = "Beijing"
print(s, age, city)

Comments