I need help interpreting a small piece of code

Hi, what does this mean? Specifically, why is there a colon in the second and third parameter, and why is there an an arrow at the end? Thanks

class Solution: 
    def twoSum(self, nums: List[int], target: int) -> List[int]:

Here is a link to the problem: https://leetcode.com/problems/two-sum/

python 3.6 introduced type hinting, which mean we could hinting the type of variable, this was done by doing variable: type. (or parameter: type), so for example target is a parameter, of type integer.

the arrow (->) allows us to type hint the return type, which is a list containing integers.


So in the case of this example, is List[int] indicative of a list type?

yes, a list type, but filled with integers.

1 Like