To take input from the user in Python and save it to a string variable, you can use the input()
function, as shown below:
main.py40 chars2 lines
This will display the prompt "Enter your text: " and wait for the user to enter their input. Once the user has entered their text and pressed enter, the input will be saved to the variable user_input
as a string.
You can then use the print()
function to display the input, as shown below:
main.py36 chars2 lines
This will display the message "You entered: " followed by the user's input.
gistlibby LogSnag