Skip to main content

Command Palette

Search for a command to run...

Day08-User Input

Updated
1 min read
Day08-User Input
C
I am Data Science student, has a little bit knowledge on Web Development. I also love writing and editing as my hobby. Passionate to explore the world.

The input() function is a built-in function that allows user input.

This input function takes input as a 'string' and gives a return value as string/character hence we have to pass that into a variable.

Example:

a = input("Enter language: ")
print("I am learning", a)

Output:

Enter language: Python #name given by user
I am learning Python #print by python

Example:

x = input("Enter first number: ") #string
y = input("Enter first number: ") #string
print (x + y) #print as it it as 'string' i.e. 458
print(int(x) + int(y)) #typecasting - convert into integar than add i.e. 53

Output:

Enter first number: 45    #45 given by user
Enter second number: 8  #8 given by user
458    #as string: 45+8=458
53     #as integar: 45+8=53

<< Previously ---------------------------------------------------- Next Lesson >>

100DaysofPython

Part 9 of 35

This series is for beginners in which we explore python language along with how it is used in data science and do some exercises and some python related projects.

Up next

Day09 - String in Python

String, Use of Backslash, Multiline, Indexing, Looping