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
4 odpowiedzi
+ 1
#You cant do that, but you can do this:
def func(x):
print(type(x))
+ 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)
0
I mean how to know what type is x in the first place not after I derlfine it?
0
Thanks alot :)