+ 2

type(x)

what does type(x) do?

13th Jun 2019, 6:10 PM
Jess Allen
Jess Allen - avatar
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'>
13th Jun 2019, 6:21 PM
Mo Hani
Mo Hani - avatar
+ 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
13th Jun 2019, 6:27 PM
Mo Hani
Mo Hani - avatar
+ 1
Yes, python. So if it checks for the type do you have to print to get <class int>
13th Jun 2019, 6:23 PM
Jess Allen
Jess Allen - avatar
+ 1
In python type(x) will return the type of the object.
13th Jun 2019, 6:25 PM
manoj
+ 1
yes. you have to print to get <class int>. e.g. print(type(2))
13th Jun 2019, 6:27 PM
manoj
+ 1
Cool thanks
13th Jun 2019, 6:29 PM
Jess Allen
Jess Allen - avatar