Skip to content

List, Tuples ,Dictionary

surendrabisht edited this page Jul 13, 2020 · 2 revisions

List -Represented by []

a collection which is ordered and changeable. Allows duplicate members.

Tuple -Represented by ()

A tuple is an immutable list of values. Tuples are one of Python's simplest and most common collection types, and can be created with the comma operator (value = 1, 2, 3).
Tuple is ordered and unchangeable. Allows duplicate members.

t = 'a', 'b', 'c', 'd', 'e'
is same as
t = ('a', 'b', 'c', 'd', 'e')

t= 2, is same as t=(2)

Does't support item assignment, i.e. cannot modify exiting values or add new values to tuple. Same like strings.

t ={(1,2,3)
x, y, z = t # this is called unpacking

Dictionary -Represented by {key:value}

It is a collection which is unordered, changeable and indexed. No duplicate members. pair of key and values.

Set-Represented by {}

Set is a collection which is unordered and un-indexed. No duplicate members.
set = {"apple", "banana", "cherry"}

Clone this wiki locally