Loading...
Loading...
00:00:00

Take user input in python

In python program if you want to take input from user you have to use built in python input() function . input() function take only string input. if you want to take int, float or other data you have to do type casting or type conversion. Input function can take multiple input at once. input() function may takes argument as string to show the user on console windows and returns the string.

In Python 3, you can take input from the user using the input() function. The input() function returns a string that represents the user's input.

Here's an example of input function:

name = input("What's your name? ")
print("Hello, " + name + "!")

In this example, the input() function prompts the user to enter their name. The user's response is stored in the name variable, and then it's used to print a greeting.

Note that the input() function always returns a string, even if the user enters a number. If you want to use the user's input as a number, you'll need to convert it to the appropriate data type, such as an int or a float, using the int() or float() functions.

For example:

x = int(input("Enter a number: "))
print(x + 1)

In this example, the user is prompted to enter a number, which is stored as a string in the x variable. The int() function is used to convert the string to an integer, which can then be used in a calculation.

Output In Python 

In Python 3, you can produce output using the print() function. The print() function takes one or more expressions as arguments, converts them to strings (if they're not already), and writes the resulting strings to the standard output.

Here's an example of print function:

print("Hello, World!")

In this example, the print() function is used to print the string "Hello, World!" to the standard output.

You can also use the print() function to print multiple expressions, separated by commas:

name = "Prity"
age = 20
print("My name is", name, "and I am", age, "years old.")

In this example, the print() function is used to print multiple expressions to the standard output. The expressions are concatenated into a single string and separated by spaces.