Why is it giving me o/p str when i give input as integer value btw 1 to 1000 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why is it giving me o/p str when i give input as integer value btw 1 to 1000

s=input() l1=[i for i in range(0,1000)] if s in l1 : print("int") else: print("str") Note1:even if it is float(eg:2.0) its ok to call it as "str" Note2: input 43a must give str

28th Jul 2020, 4:05 AM
Sinchana
Sinchana - avatar
3 Answers
+ 2
Hi remember that python input is by default a string result, so if you want to achieve what you want you have to cast your input into a integer, like this s=int(input())
28th Jul 2020, 4:13 AM
Erick Ventura
Erick Ventura - avatar
+ 1
Im sorry but the question has a string input - you have been using ast.literal.eval() to take input in a suitable format . Have you thought of how does it distinguish btw different types of data structures? You will be given a string as input . U have to determine int or str ? This is also encountered in data science. Upon taking a lot of data , sometimes integer values are treated as string, eg : 43a is str 12.4 is str
28th Jul 2020, 4:19 AM
Sinchana
Sinchana - avatar
0
input() function in python can only access data in the form of strings data type only... To convert that to required suitable type, we have type casting methods.. So ex : 1 is different from "1"...
28th Jul 2020, 1:53 PM
Jayakrishna 🇮🇳