Python provides developers with built-in functions that can be used to get input directly from users and interact with them using the command line (or shell as it is often called).
In Python 2, raw_input() and in Python 3, we use input() function to take input from Command line.- Python 2 raw_input() function
- Python 3 input() function
If we execute the below code, program prompts the user for "Enter Your Name". Enter the name and the press "Enter" key on your keyboard. As we see below next statement "print(name)" is executed.
name = raw_input("Enter Your Name!")
print("printing name",name)
To prompt the input on the next line, add "\n" to raw_input() function as shown below.
name = raw_input("Enter Your Name!\n")
print("printing name",name)
name = input("Enter Your Name!")
print("printing name",name)
Related Notebooks
- How To Take Integer Input From Command Line In Python
- Five Ways To Remove Characters From A String In Python
- Python Pandas String To Integer And Integer To String DataFrame
- String And Literal In Python 3
- How To Add Regression Line On Ggplot
- Write Single And Multi Line Comments In Python
- How To Run Code From Git Repo In Collab GPU Notebook
- Return Multiple Values From a Function in Python
- How to Plot a Histogram in Python