0

In the python definition of functions.how the language determine the type of the variables in the () ?

Def func(x): Print(x) How to tell if x is a string or a float or an integer

13th Jul 2019, 10:52 AM
omar alkhafif
omar alkhafif - avatar
4 odpowiedzi
+ 1
#You cant do that, but you can do this: def func(x): print(type(x))
13th Jul 2019, 11:08 AM
Seb TheS
Seb TheS - avatar
+ 1
You can not really specify the type of the arguments you want to pass in, but you can make it raise an error if wrong arguments were given. def func(x): assert isinstance(x, int), "x must be an integer" print(x)
13th Jul 2019, 11:52 AM
Seb TheS
Seb TheS - avatar
0
I mean how to know what type is x in the first place not after I derlfine it?
13th Jul 2019, 11:19 AM
omar alkhafif
omar alkhafif - avatar
0
Thanks alot :)
13th Jul 2019, 2:03 PM
omar alkhafif
omar alkhafif - avatar