Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

TypeScript arrays and Python lists handle many of the same everyday collection tasks, but they are not identical. TypeScript describes the element types of JavaScript arrays with annotations such as number[]; Python’s built-in list can hold objects of different types, even when a type annotation documents an intended element type.

How TypeScript arrays and Python lists differ

TypeScript uses JavaScript arrays at runtime and adds static type descriptions that help catch mistakes while code is checked. For example, number[] and Array<number> both describe an array whose elements are intended to be numbers. These annotations do not create different runtime containers.

const scores: number[] = [10, 20, 30];
const alsoScores: Array<number> = [10, 20, 30];

Python’s built-in list is a mutable sequence that can contain arbitrary Python objects. An annotation can express the intended element type, but the built-in list itself is not restricted to that type.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Map common operations by intent

These pairs solve similar tasks, but they are language-specific operations rather than exact equivalents.

#1 Best Overall
Task TypeScript / JavaScript array Python list
Add an item at the end items.push(value) items.append(value)
Get the number of items items.length len(items)
Check whether a value is present items.includes(value) value in items
Take a portion of a sequence items.slice(start, end) items[start:end]

For example, the membership check changes order: TypeScript calls a method on the array, while Python places the value before in. Slicing is also expressed differently: the TypeScript call uses parentheses and the Python form uses brackets with a colon.

Account for Python methods that mutate a list

Python’s append, reverse, and sort methods modify the existing list. The methods return None, rather than returning the changed list for chaining.

values = [3, 1, 2]
values.append(4)
values.sort()

# values is now [1, 2, 3, 4]

When translating code, keep the mutation separate from the value being changed. Do not assign the result of a mutating Python list method back to the list.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Use tuples when positions matter

A TypeScript tuple describes a positional shape: [string, number] means the first position is a string and the second is a number. This is useful for a fixed pair with different roles, rather than a collection where each item has the same type.

Python also has tuples, but they are not simply another spelling for a list. Lists are mutable; tuples are immutable and commonly represent fixed collections of values. As a guide, use a Python list for a sequence you intend to change, and a tuple for a fixed group. In TypeScript, use an array type for a collection and a tuple type when positions have specific meanings.

Quick Recap

SaleBestseller No. 1
Bestseller No. 4
Python Programming Logo for Programmers T-Shirt
Python Programming Logo for Programmers T-Shirt
Vintage and Distressed Python Programming Language design.; Lightweight, Classic fit, Double-needle sleeve and bottom hem
$19.99
Rank #4
Python Programming Logo for Programmers T-Shirt
  • Python Programming Language design with distressed logo for Python Software Engineers and Developers.
  • Vintage and Distressed Python Programming Language design.
  • Lightweight, Classic fit, Double-needle sleeve and bottom hem

A practical translation checklist

  • Choose a TypeScript element type such as number[] when the collection is intended to contain numbers; Python’s built-in list does not enforce a single element type by itself.
  • Translate the operation’s purpose, not just its spelling: use append for adding to a Python list, len for its size, and value in items for membership.
  • Check whether an operation mutates the original list, especially when using Python’s append, reverse, or sort.
  • Use positional tuple types or values when the meaning depends on what each slot contains, rather than treating every sequence as interchangeable.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.