Member-only story
Python 101 — input() function and Variables
8 min readSep 24, 2023
This chapter introduces the use of the input() function and variables, while also addressing common coding errors that may arise in any coding adventure.
input() Definition
The input() function is a built-in Python function that allows you to accept user input from the keyboard during the execution of a Python program. It reads a line of text from the user and returns that input as a string.
ask_for_name = input("What is your name? ")
This will prompt the question and will wait for the user’s input.
Key Points:
- Return Type: input() always returns a string, even if the user enters a number or other data type. If you want to work with numbers, you'll need to convert the input to the appropriate data type (e.g., int() or float()).
- Blocking: When input() is encountered, it pauses the program's execution until the user provides input and presses the Enter key.
- User Input: Users can enter any text, including numbers, letters, and symbols. It reads the input until the user presses Enter, which signifies the end of the input.
- Whitespace: input() includes any leading and trailing whitespace (e.g., spaces or tabs) entered by the user in the returned string…