+ 1

Why it doesn't print elements with numbers?

https://code.sololearn.com/cZ8M592tIUIv/?ref=app

25th Jan 2020, 5:50 PM
Baran Aldemir
Baran Aldemir - avatar
6 Answers
+ 3
You write: number==int Instead use: type(number) is int or: isinstance(number, int) number is, well a number and int is the type int. It's a different thing, not equal. Instead you want to know if the type of number is int.
25th Jan 2020, 5:56 PM
HonFu
HonFu - avatar
+ 2
Because of: number == int int is a class and no integer is equal to the class.
25th Jan 2020, 5:56 PM
Seb TheS
Seb TheS - avatar
+ 1
Seb TheS 5.0 == int results in True. I don't understand.
25th Jan 2020, 6:02 PM
Baran Aldemir
Baran Aldemir - avatar
+ 1
liste = ["345","sadas","324a","14","kemal"] for i in liste: for x in i: try: number = int(x) print(number) except: continue
25th Jan 2020, 6:03 PM
rodwynnejones
rodwynnejones - avatar
+ 1
Baran Aldemir int is a class. 5 == int ---> False 5.0 == int ---> False 5.0 == 5 ---> True
25th Jan 2020, 6:04 PM
Seb TheS
Seb TheS - avatar
+ 1
Seb TheS Oh sorry. You're right it returns false.I misremembered it.
25th Jan 2020, 6:07 PM
Baran Aldemir
Baran Aldemir - avatar