+ 2

Can anyone help me yar

Can we use like this in python For ex: If type(c)=='int': If type(c)=='char' I m strucking due to this

7th May 2021, 11:16 AM
Keerthi goli
Keerthi goli - avatar
16 ответов
+ 4
Keerthi goli ya! You can use the way you want Like--- If type(c)==int: If type(c)=='char' data1 = 10 data2 = "go" if type(data1) ==int: print("i am believer") And ya it is absolutely fine... Hope I helped you 👍👍
8th May 2021, 10:06 AM
คгשเภ๔ кย๓คг
คгשเภ๔ кย๓คг - avatar
+ 3
You can use it like this a=5 if type(a) is int: print("working")
7th May 2021, 11:26 AM
YUGRAJ
+ 2
Yes , is operator is used for data types instead of == Like type(c) is int : returns either True or False .
7th May 2021, 11:28 AM
Akshay Panwar
Akshay Panwar - avatar
+ 1
Keerthi goli By 'k', I mean the data which you have to work on.
7th May 2021, 1:16 PM
Calvin Thomas
Calvin Thomas - avatar
+ 1
I went by ((ord(i)>=65 and ord(i)<=90) or (ord(i)>=97 and ord(i)<=122) for char And also int Compiler doesn't taking it
7th May 2021, 1:44 PM
Keerthi goli
Keerthi goli - avatar
+ 1
What you want to do exactly?
7th May 2021, 6:42 PM
Pranav Hirani
Pranav Hirani - avatar
0
Is it work!
7th May 2021, 11:27 AM
Keerthi goli
Keerthi goli - avatar
0
Yeah you can run my code
7th May 2021, 11:27 AM
YUGRAJ
0
Is it also applicable for char that I m getting undefined 'char'
7th May 2021, 11:31 AM
Keerthi goli
Keerthi goli - avatar
0
I don't think python has separate data type for character a character is basically a string of length 1
7th May 2021, 11:34 AM
YUGRAJ
0
Keerthi goli type() returns a class. So if you want to compare teo classes, you may use the 'is' keyword. The '==' keyword only checks if the values are equal, which also works here. type(k) == int Or type(k) is int Works
7th May 2021, 1:13 PM
Calvin Thomas
Calvin Thomas - avatar
0
But,type(k) also not working 😑
7th May 2021, 1:14 PM
Keerthi goli
Keerthi goli - avatar
0
Type(k) is int also not working
7th May 2021, 1:15 PM
Keerthi goli
Keerthi goli - avatar
0
Yeah!! I understood But it's not working !!
7th May 2021, 1:17 PM
Keerthi goli
Keerthi goli - avatar
0
Keerthi goli Please check this out: data1 = 56 data2 = "ahj" print(type(data1) is int) print(type(data2) is str) # Hope this helps
7th May 2021, 1:34 PM
Calvin Thomas
Calvin Thomas - avatar
0
Hello
8th May 2021, 1:43 PM
temitope