Member-only story

Python 101 — input() function and Variables

Adina Socaci
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:

  1. 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()).
  2. Blocking: When input() is encountered, it pauses the program's execution until the user provides input and presses the Enter key.
  3. 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.
  4. Whitespace: input() includes any leading and trailing whitespace (e.g., spaces or tabs) entered by the user in the returned string…

--

--

Adina Socaci
Adina Socaci

Written by Adina Socaci

Tech | Science | Languages | Having Fun

No responses yet