Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python3 function definition, arrow and colon [duplicate]

I have found the following python function definition:

def reverseString(self, s: 'List[str]') -> 'None':

I don't quite understand 'List[str]' and -> 'None'.

I have found that the arrow is a function annotation but I couldn't find anything useful and understandable for List[str].

Is it just an annotation? or does it enforce that the type of parameter s must be a string array?

like image 872
Amir Avatar asked Feb 06 '19 10:02

Amir


People also ask

What is the meaning of -> in Python?

It's a function annotation. In more detail, Python 2. x has docstrings, which allow you to attach a metadata string to various types of object. This is amazingly handy, so Python 3 extends the feature by allowing you to attach metadata to functions describing their parameters and return values.

What does the arrow mean in Python 3?

Python doesn't use arrow notation, like JavaScript — so what is this arrow doing? This, friend, is a return value annotation, which is part of function annotation, and it's a feature of Python 3 - and has been here since 3.0!

What does * mean in Python function?

Practical Data Science using Python The asterisk (star) operator is used in Python with more than one meaning attached to it. For numeric data types, * is used as multiplication operator >>> a=10;b=20 >>> a*b 200 >>> a=1.5; b=2.5; >>> a*b 3.75 >>> a=2+3j; b=3+2j >>> a*b 13j.

What does arrow in Python function mean?

Arrow is a Python module for working with date and time. It offers a sensible and human-friendly approach to creating, manipulating, formatting and converting dates, times and timestamps. It allows easy creation of date and time instances with timezone awareness.


1 Answers

It's just python type hinting, You can learn more in PEP 484

like image 169
Aliakbar Saleh Avatar answered Nov 03 '22 07:11

Aliakbar Saleh