Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does rtype mean in Python?

When I do some code tests, there are some comments below the solution function like this:

"""
:type x: int
:rtype: int
"""

x is my only input, so what does rtype stand for?

like image 698
Jingyuan Avatar asked Aug 02 '18 10:08

Jingyuan


People also ask

What is Rtype in Python?

rtype: Return type. The type() function either returns the type of the object or returns a new type object based on the arguments passed.,If you need to check the type of an object, it is better to use the Python isinstance() function instead.

What is a Docstring in Python?

A Python docstring is a string used to document a Python module, class, function or method, so programmers can understand what it does without having to read the details of the implementation. Also, it is a common practice to generate online (html) documentation automatically from docstrings.


2 Answers

To avoid confusion:

type:    Type of a parameter.
vartype: Type of a variable. 
rtype:   Return type. 
like image 58
Saurav Sahu Avatar answered Oct 23 '22 15:10

Saurav Sahu


It's the abbreviation for "return type".

See the Sphinx documentation for more information on field names and examples.

like image 33
IonicSolutions Avatar answered Oct 23 '22 16:10

IonicSolutions