In this post, we will look at an interesting part of any programming language.
Yes, you guessed it right. We will read about how to take input from a user and print it in python.
To take user input we have “input()” function available in python.
Lets see an example to understand it.
Taking user input of a String & Integer
user@ngelinux$ cat input.py #!/usr/local/bin/python3 name=input("Please enter your name : ") age=input("Your age : ") print ("Welcome ", name, ". You are", age, "years old") user@ngelinux$
user@ngelinux$ ./input.py Please enter your name : saket Your age : 12 Welcome saket . You are 12 years old
In the above example, we can see input function is used to take input of string and integer both.
So now its very easy to take user input and to understand the program.