LA ILAHA ILLA HU
Allah, Your Lord There Is No Deity Except Him.
Lesson 3: Python input() Function In Python Coding
In simple words input() function in Python ask the user to enter some data for example it may be his name age etc and prints it.Example code asking the user to enter his name.
Python Code For Type Input() Function
Enter your name:
Or any name entered by user
About This Code
You can type/copy paste the above code in any online compiler or editor or you can even practice to write the code by hand.In the 1st line of examlpe code above the user is asked to enter his name.
The seond line of code defines a variable x = input()
Furthermore as the variable is defined as x when the user writes his name it is stored.
in variable x The 3rd line of code specifies that the name will be printed with Hello.
How it works?
To capture the input in your program, you will need a variable. A variable is a container to hold data. (You can learn more on variables visiting the variables link on your left.) You can take the input and assign it to a variable.
This is done using the = operator before the input keyword and then putting the variable name before the = operator.
In the example code above this is done by x = input()
Important points to remember about input
In Python, we use input() function to take input from the user. Whatever you enter as input, the input function converts it into a string.
If you enter an integer value still input() function convert it into a string.
Output using the print() function
To output your data to the screen, use the print() function. You can write print()
This will print the argument in the next line when you press the ENTER key.
For example, if your data is "Moon," you can put "Moon" inside the parentheses ( ) after print.
print("Moon")
And the output for the above will be
Moon