[Solved] What is the default type of the input that we give in python using input() function? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

[Solved] What is the default type of the input that we give in python using input() function?

This is my code: def maxnum(a, b): if a >= b: print(a) else: print(b) x = input() y = input() maxnum(x, y) For the input 5 12 I'm getting output as 5 What is the problem?

3rd Mar 2017, 9:05 PM
Maaz
Maaz - avatar
3 Answers
+ 4
The default is a string. So, if you know an extensive amount about computers, "5" is greater than "1" (the first letter) on the ASCII chart. If you want to convert it to an integer, just put int() around your input. For example: x = int(input()) y = int(input())
3rd Mar 2017, 9:23 PM
Keto Z
Keto Z - avatar
+ 3
by default input() is a str, that's why you have to manually convert it to an int by using int(input())
4th Mar 2017, 12:12 AM
ramzi
ramzi - avatar
+ 1
Oh, alright.. yeah i knew about the ASCII value but i was thinking it would interpret the type of value here too. Just like it does in x = 12 Here it interprets it as int Thank you for the answer :)
3rd Mar 2017, 9:38 PM
Maaz
Maaz - avatar