Input Output In Python
In Python, input and output operations are handled through functions and methods provided by the language. Here are the primary ways to perform input and output in Python:
- Input: To receive input from the user, you can use the
input()
function. It reads a line of text entered by the user from the console and returns it as a string. You can assign the input to a variable for further processing.
for string:
name = input(“Enter your name: “)
print(“Hello, ” + name)
for int:
age =int( input(“Enter your age: “))
print(“you are”,age,”year old”)
for float:
height = float(input(“Enter your height: “))
print(“Hello, your height is ” + height)
- Output: To display output to the console or terminal, you can use the
print()
function. It takes one or more arguments and prints them to the console. The arguments can be strings, variables, or expressions that are automatically converted to strings.