Python - Python Object classifications

Introduction

Object typeCategory Mutable?
Numbers (all) Numeric No
Strings (all) SequenceNo
Lists Sequence Yes
DictionariesMappingYes
Tuples Sequence No
Files ExtensionN/A
SetsSet Yes
Frozenset Set No
bytearray Sequence Yes

Rule:

  • Lists, dictionaries, and tuples can hold any kind of object.
  • Sets can contain any type of immutable object.
  • Lists, dictionaries, and tuples can be arbitrarily nested.
  • Lists, dictionaries, and sets can dynamically grow and shrink.

An example of nesting.

Demo

L = ['abc', [(1, 2), ([3], 4)], 5] 
print( L[1] )#  w w  w.  jav a 2  s .  c  om
print( L[1][1] )
print( L[1][1][0] )
print( L[1][1][0][0] )

Result

Related Topic