Some add-on modules for Python will include the exact argument and return types of their functions in the docs, just like you'd see in Java. The Python Standard Library documentation doesn't do this, but you can usually still figure it out by reading the description of the function and thinking about what makes sense for the function to return. Here's an example
Python Standard Library documentation wrote:
Beta distribution. Conditions on the parameters are alpha > 0 and beta > 0. Returned values range between 0 and 1.
The description says the function returns a value "between 0 and 1". So the function has to return a number, but it can't be an int
because there are no int
s between 0 and 1, so it has to be a float
If it's hard to figure out the type from the documentation, you can also try opening up a Python console and running the function to see what it returns:
Also, keep in mind that in Python, it doesn't really matter what type a variable is so long as it has the methods and properties you need. (This is sometimes called "duck typing".) If you write x.endswith(".com")
in your Python program, x
could be a string, but it could also be some other class that has a method named endswith
. So another strategy for dealing with types in Python is to not worry too much about them.