It is a so called "type hint" (or "function annotation"; these are available since Python 3.0).

  • -> List[int] means that the function should return a list of integers.
  • nums: List[int], target: int means that nums is expected to be a list of integers and that target is expected to be an integer.

This is not a hard requirement, though, i.e. you can still call the function with objects of different types passed for these parameters and the function can as well return something different than a list of intergers (unlike in other languages like Java where providing wrong types would result in a compile error). To put it differently: Type hints are irrelevant for the program execution, they are ignored at runtime (ignoring the type hints is just the default behavior, but they are available at runtime via __annotations__, so you could do something with them).

Type hints can express the intent of the author and can be checked before program execution by tools like mypy (these can check e.g. that a function is only called with parameters of the correct type and returns something of the correct type).

Note that List is not available in the standard namespace (unlike list), but (at least before Python 3.9) instead needs to be imported from typing which also

  • provides other types for standard types, like Set, Dict, Tuple, Callable etc.
  • allows to define own types
  • provides typed versions of other types, like NamedTuple instead of namedtuple

From Python 3.9 on, one could as well use the standard list constructor for the type hint, see here.

Answer from Michael H. on Stack Overflow
Top answer
1 of 2
31

It is a so called "type hint" (or "function annotation"; these are available since Python 3.0).

  • -> List[int] means that the function should return a list of integers.
  • nums: List[int], target: int means that nums is expected to be a list of integers and that target is expected to be an integer.

This is not a hard requirement, though, i.e. you can still call the function with objects of different types passed for these parameters and the function can as well return something different than a list of intergers (unlike in other languages like Java where providing wrong types would result in a compile error). To put it differently: Type hints are irrelevant for the program execution, they are ignored at runtime (ignoring the type hints is just the default behavior, but they are available at runtime via __annotations__, so you could do something with them).

Type hints can express the intent of the author and can be checked before program execution by tools like mypy (these can check e.g. that a function is only called with parameters of the correct type and returns something of the correct type).

Note that List is not available in the standard namespace (unlike list), but (at least before Python 3.9) instead needs to be imported from typing which also

  • provides other types for standard types, like Set, Dict, Tuple, Callable etc.
  • allows to define own types
  • provides typed versions of other types, like NamedTuple instead of namedtuple

From Python 3.9 on, one could as well use the standard list constructor for the type hint, see here.

2 of 2
5

It's a new feature in version 3.5. You can see the docs.
https://docs.python.org/3.5/library/typing.html

🌐
Snakify
snakify.org β€Ί lists
Lists - Learn Python 3 - Snakify
If you want to read a list of real numbers, you have to change the type int to float. The method split() has an optional parameter that determines which string will be used as the separator between list items.
🌐
Stack Overflow
stackoverflow.com β€Ί questions β€Ί 68848919 β€Ί creating-a-list-of-integers-in-python
Creating a list of integers in Python - Stack Overflow
Is it possible to create a list of integers with a single line of code, without using any third-party libraries? I tried with the syntax: lst = list(int(1234)) or the syntax: lst = list(int(1,2,3,...
🌐
PythonForBeginners.com
pythonforbeginners.com β€Ί home β€Ί list of strings to list of integers in python
List of Strings to List of Integers in Python - PythonForBeginners.com
April 1, 2022 - To handle the error, you can use exception handling in python using the try-except blocks. Inside the for loop, we will convert the element to an integer using the int() function in the try block before appending it to the output_list. In the except block, we will print each element that cannot be converted to an integer.
🌐
W3Schools
w3schools.com β€Ί python β€Ί python_lists.asp
Python Lists
Lists are used to store multiple items in a single variable.
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί python β€Ί python-convert-number-to-list-of-integers
Python - Convert Number to List of Integers - GeeksforGeeks
For instance, the number 12345 can be converted to the list [1, 2, 3, 4, 5]. Let's discuss several methods to achieve this conversion. Combination of str() and map() is a straightforward and efficient way to convert a number into a list of integers.
Published: July 11, 2025
🌐
Finxter
blog.finxter.com β€Ί how-to-convert-a-string-list-to-an-integer-list-in-python
How to Convert a String List to an Integer List in Python – Be on the Right Side of Change
April 9, 2021 - The most Pythonic way to convert a list of strings to a list of ints is to use the list comprehension [int(x) for x in strings]. It iterates over all elements in the list and converts each list element x to an integer value using the int(x) built-in function.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί python β€Ί python-converting-all-strings-in-list-to-integers
Converting all Strings in a List to Integers - Python - GeeksforGeeks
July 11, 2025 - map() function applies a given function to all elements in an iterable. Here, we use map(int, a) to convert each string in the list to an integer. ... List comprehension provides a more Pythonic and concise way to convert a list of strings to ...
🌐
Medium
medium.com β€Ί @aleksej.gudkov β€Ί how-to-convert-numbers-in-a-list-using-the-int-function-e20425dface6
How to Convert Numbers in a List Using the int() Function | by UATeam | Medium
November 24, 2024 - Converting numbers in a list to integers is a common task in Python, especially when working with data from external sources where numbers might be represented as strings. Python’s built-in int() function makes this conversion simple and efficient.
🌐
LabEx
labex.io β€Ί tutorials β€Ί python-how-to-work-with-lists-of-integers-in-python-417500
How to work with lists of integers in Python | LabEx
Integers are whole numbers, both positive and negative, and they are one of the most common data types used in programming. In Python, a list of integers can be created using square brackets [] and the integers separated by commas.
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί python β€Ί python-integers-string-to-integer-list
Python - Integers String to Integer List - GeeksforGeeks
July 15, 2025 - This method is compact and often more readable than traditional loops, making it ideal for transforming or filtering elements of a list or string. ... # Input string of integers s = "1 2 3 4 5" # Convert the string to a list of integers using list comprehension int_list = [int(i) for i in s.split()] # Print the result print(int_list)
🌐
Stack Abuse
stackabuse.com β€Ί bytes β€Ί add-integers-to-a-list-in-python
Add Integers to a List in Python
July 1, 2022 - One of the most common ways to add an integer to a list, let alone any other type of data, is to use the append() method.
🌐
Medium
medium.com β€Ί @nawazmohtashim β€Ί converting-a-list-to-integer-in-python-exploring-methods-and-techniques-db527fcc583a
Converting a List to Integer in Python: Exploring Methods and Techniques | by Mohd Mohtashim Nawaz | Medium
December 13, 2023 - Lists are defined by enclosing elements within square brackets [] and separated by commas. ... Converting a list to an integer involves aggregating its elements into a single numerical value.
🌐
Python Help
pythonhelp.org β€Ί tutorials β€Ί convert-list-to-int
How to convert a list to int in Python
September 23, 2024 - Before diving into the methods, it’s essential to understand the basic concept of data types in Python. A list is a collection of items, which can be of different data types, while an integer is a whole number without a fractional component.
🌐
Plain English
python.plainenglish.io β€Ί three-awesome-ways-to-get-a-list-of-integers-as-input-in-python-2325e5a9e91e
How to get Input for a List of Integers in Python? | Python in Plain English
July 30, 2023 - These are the three easy ways to get input for a list of integers in Python: 1. Using a for loop 2. Using list comprehension 3. Using the map class
🌐
Finxter
blog.finxter.com β€Ί 5-best-ways-to-create-a-list-of-ints-in-python
5 Best Ways to Create a List of Ints in Python – Be on the Right Side of Change
February 24, 2024 - The iter() function and generator expressions can be used to build an integer list. ... This code creates a list of nine ones. The iter() function is called with a lambda function always returning 1, and the stop condition 1. A generator expression then limits the list size to numbers less than 10.
🌐
Moonbooks
en.moonbooks.org β€Ί Articles β€Ί How-to-create-a-list-of-numbers-in-python-
How to Create a List of Numbers in Python - Moonbooks
March 9, 2018 - Here are the most common ways to create lists of numbers in Python: Use list(range()) for simple integer lists. Use list comprehensions when you need filtering or transformations.
🌐
freeCodeCamp
freecodecamp.org β€Ί news β€Ί create-a-list-in-python-lists-in-python-syntax
Create a List in Python – Lists in Python Syntax
March 23, 2022 - Lists are one of the core data structures in Python. We use them for storing any data type, whether it's an integer, string, boolean, or even an object.
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί python β€Ί python-create-list-of-numbers-with-given-range
Create List of Numbers with Given Range - Python - GeeksforGeeks
Explanation: np.arange(r1, r2).tolist() uses NumPy's arange() function to generate a sequence of numbers from r1 o r2 .tolist() method converts the NumPy array into a Python list.
Published: July 11, 2025