0

How do we get to know when any number we print is an integer or string?

Like print("42") here 42 is a string as told in the tutorial how do we get to know that.

29th Aug 2021, 12:27 PM
RAHUL SHARMA
5 odpowiedzi
+ 3
Hi RAHUL! Always remember, anything inside the quotes is a string. It can be an integer or text. For example, a = 42 is an integer a = "42" is a string b = 42.0 is a float(decimals) b = "42.0" is a string
29th Aug 2021, 4:29 PM
Python Learner
Python Learner - avatar
+ 2
U can use print(type(21)) Output <class 'int'> Int is the type
29th Aug 2021, 12:40 PM
Pariket Thakur
Pariket Thakur - avatar
+ 1
a="42" print(type(a),type(a)==str,isinstance(a,str))
29th Aug 2021, 12:38 PM
Abhay
Abhay - avatar
+ 1
''' this function will return the type of it it also kindly prints it out for debugging purposes ''' def print_what_this_is(this,): print(this.__class__.__name__) return this.__class__.__name__ #examples #run it print_what_this_is(2) print_what_this_is('uwu') print_what_this_is([])
30th Aug 2021, 12:03 AM
⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀ - avatar
0
U can simply use type(x) to get the type of x. Type(True) will give boolean Type(1) will give int Type ("46") Will give string So on
31st Aug 2021, 4:32 AM
Utkarsh Gautam