Prompting for User Input in Python using input()

# Python From Zero To One — Part 7

Liu Zuo Lin


Day 31 of experimenting with video content

input() in a nutshell

name = input('what is your name? ')

^ the built-in input() function allows us to prompt the user to type in something eg. name, age etc.

Whatever the user types will be stored as a string value in the name variable (even if we type a number)

input() but with numbers

let’s say we want to let the user enter 2 numbers, and then print their sum.

num1 = input('enter number 1: ')
num2 = input('enter number 2: ')

print(int(num1) + int(num2))
  • input() always returns a string value
  • so if we want to work with numbers, we have to do the appropriate type casting to convert them into int/float


Hope this was clear and easy to understand.

Some Final words

If this story was helpful and you wish to show a little support, you could:

  1. Clap 50 times for this story
  2. Leave a comment telling me what you think
  3. Highlight the parts in this story that resonate with you

These actions really really help me out, and are much appreciated!

Ebooks I’ve Written: