Prompting for User Input in Python using input()

# Python From Zero To One — Part 7

Liu Zuo Lin
2 min readDec 2, 2023

Day 31 of experimenting with video content

input() in a nutshell


name = input('what is your name? ')
print(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

Conclusion

--

--