What is a sequence data type in Python?

PythonServer Side ProgrammingProgramming

Sequences allow you to store multiple values in an organized and efficient fashion. There are several sequence types: strings, Unicode strings, lists, tuples, bytearrays, and range objects. Dictionaries and sets are containers for non-sequential data.

From the official Python Docs −

  • Strings are immutable sequences of Unicode code points.

  • Lists are mutable sequences, typically used to store collections of homogeneous items.

  • Tuples are immutable sequences, typically used to store collections of heterogeneous data (such as the 2-tuples produced by the enumerate() built-in).

  • Bytearray objects are mutable, they support the mutable sequence operations in addition to the common bytes and bytearray operations

  • The range type represents an immutable sequence of numbers and is commonly used for looping a specific number of times in for loops.

Published on 05-Jan-2018 12:19:22