Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the mechanism for `def twoSum(self, nums: List[int], target: int) -> List[int]:` in python 3:

Ifound the code as follow in python3:

def twoSum(self, nums: List[int], target: int) -> List[int]:
    return sum(nums)

As I know for python def, we only need follow:

def twoSum(self, nums, target):
    return sum(nums)

what is the nums: List[int], target: int and ->List[int] means? Are those new features of python 3? I never see those.

Thanks,

like image 961
jason Avatar asked Jun 17 '19 16:06

jason


1 Answers

from typing import List

def twoSum(nums: List[int], target: int) -> List[int]:
    print(nums, target)

Link: https://docs.python.org/3/library/typing.html

Note The Python runtime does not enforce function and variable type annotations. They can be used by third party tools such as type checkers, IDEs, linters, etc.

Link: https://code.visualstudio.com/docs/python/linting

like image 105
Muhammad Rizwan Avatar answered Oct 03 '22 03:10

Muhammad Rizwan