If our Python programme needs to take any input from user then we can input() function.
Example of Python input:
1 2 |
name = input('What is your name?') print(name) |
In the above example, we are asking user to provide us their name using input function. The user input name is then saved into the name variable. Finally the name is then displayed using print function
Example of input with concatenation:
1 2 3 |
name = input('What is your name?') age = input('What is your age?') print("Your name is " + name + " and your age is " + age) |
In the above example, we have used input function for accepting user’s name and age values. Both values are saved into variables name and age. Using the + sign we have concatenated the text (string) message (like “your name is” and “your age is”) with the variable values of name and age. Concatenation is explained in another lesson.