python 3.x what is -> annotation
<p>In the following snippet what is <code>-&gt;</code> operator ,does it indicate the return type of the function also is it mandatory to use it in python 3.x ? Please point me to few docs for the same</p>

<pre><code> def g() -&gt; str :
    ...
    return 'hello world'
</code></pre>

<p><code>-&gt;</code> is an <a href="https://www.python.org/dev/peps/pep-3107/" rel="nofollow"><em>annotation</em></a>, attached to the function <em>return value</em>. Annotations are optional, but you can use the syntax to attach arbitrary objects to a function. You can attach more annotations by using <code>name : annotation</code> on the parameters too.</p>

<p>In the sample you gave, it is being used to create a <em>type hint</em>. Type hinting is a new Python 3 extension. It is <em>not</em> mandatory, but using type hints can make development in an IDE like PyCharm easier, as well as enable static typechecking by tools like <a href="http://mypy-lang.org/" rel="nofollow">mypy</a>.</p>

<p>See the <a href="https://docs.python.org/3/library/typing.html" rel="nofollow"><code>typing</code> module</a> for a set of objects to help create type hints, and the <a href="https://www.python.org/dev/peps/pep-0484/" rel="nofollow">PEP 484 <em>Type Hints</em></a> proposal.</p>

python