+ 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
16 Answers
+ 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 👍👍
+ 3
You can use it like this
a=5
if type(a) is int:
print("working")
+ 2
Yes , is operator is used for data types instead of ==
Like
type(c) is int : returns either True or False .
+ 1
Keerthi goli By 'k', I mean the data which you have to work on.
+ 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
+ 1
What you want to do exactly?
0
Is it work!
0
Yeah you can run my code
0
Is it also applicable for char that I m getting undefined 'char'
0
I don't think python has separate data type for character a character is basically a string of length 1
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
0
But,type(k) also not working 😑
0
Type(k) is int also not working
0
Yeah!! I understood
But it's not working !!
0
Keerthi goli Please check this out:
data1 = 56
data2 = "ahj"
print(type(data1) is int)
print(type(data2) is str)
# Hope this helps
0
Hello