taking input and saving to string in python

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.py
user_input = input("Enter your text: ")
40 chars
2 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.py
print("You entered: " + user_input)
36 chars
2 lines

This will display the message "You entered: " followed by the user's input.

gistlibby LogSnag