+ 2

Int() not working

Sample input: take1= input("a") int(take1) print(take1 == type(int)) print(take1 == type(str)) print(type(take1)) Sample output False False <class "str" > #this does not make sense to me

16th Sep 2021, 1:14 AM
Richard
Richard - avatar
5 Antworten
+ 2
Dear Python learner .The solution is to do it like this: Take = int(Take) If you do this: Take = int() #it will create an empty integer = 0
18th Sep 2021, 2:26 AM
Richard
Richard - avatar
+ 3
Hi again! That's because, this is not a proper way to convert a string to an integer. You can do it like this take2 = int(take1) This is how type() function is used to compare a variable type. type(take1) == int type(take1) == str and so on
16th Sep 2021, 1:34 AM
Python Learner
Python Learner - avatar
+ 2
Best Way to Get Numbers From String: x=input() lst=[] for i in x: if i.isdigit(): lst.append(i) else: None print(''.join(lst))
16th Sep 2021, 1:26 PM
Sancho Godinho
Sancho Godinho - avatar
0
Python learner is amazing
16th Sep 2021, 1:46 AM
Richard
Richard - avatar
0
Try to put int and str in quotes
17th Sep 2021, 4:05 PM
Kittu
Kittu - avatar