+ 2
type(x)
what does type(x) do?
6 Respostas
+ 2
I suppose you're talking about python, in python there is a built-in function called type, it checks for the type of the object x, integer or string or tuple and so on.
Examples:
type(2) <class 'int'>
type("Hi") <class 'str'>
+ 2
Yes you need the print statement to output it's type, it can be used without print for other purposes like: if type(x) == int
+ 1
Yes, python.
So if it checks for the type do you have to print to get <class int>
+ 1
In python type(x) will return the type of the object.
+ 1
yes. you have to print to get <class int>. e.g. print(type(2))
+ 1
Cool thanks