Day08-User Input

Day08-User Input

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 >>