Sideway
output.to from Sideway
Draft for Information Only

Content

Python Collection Literal
 Features of Python Collection Literal
 List Literals
 Tuple Literals
 Dictionary Literals
 Set Literals
    Frozenset Literals
 Source and Reference

Python Collection Literal

Besides, scalar literal, Python also support collection literals. Literal collections is a collection of literals featured by the form of collections. The typical literal collections are list literal, tuple literal, dictionary literal, set literal, and frozenset literal.

Features of Python Collection Literal

LiteralElementArrangementMutabilityDuplicate Member Example ListitemOrderedMutableAllow [], [5,6,8] TupleitemOrderedImmutableAllow (), (5,6,7) Dictionarykey-value UnorderedMutableNot Allow{}, {'x':5} SetitemUnorderedMutableNot Allow Set(), {85,6,7} FrozensetitemUnorderedImmutableNot Allowfrozenset(), frozenset({85,6,7})

List Literals

A list literal is a container used to contain a variable length sequence of Python objects. Elements of list can be Python objects of other types. Python objects in the list are ordered, changeable, and allowing duplicate members. A list lteral is enclosed by a pair of square brackets with elements in the list are separated by commas ,. An extra comma at the end of the List will always be ignored. An empty List can be created by a pair of square brackets with no element inside. image

Tuple Literals

A tuple literal is a container used to contain a fixed length sequence of Python objects. Elements of tuple can be Python objects of other types. Python objects in the tuple are ordered, unchangeable, and allowing duplicate members. A tuple is enclosed by a pair of parentheses with elements in the list are separated by commas ,. An extra comma at the end of the Tuple will always be ignored. However, when there is only one element in the tuple, a comma must be at the end in order to indicate that the element is a tuple. An empty Tuple can be created by a pair of parentheses with no element inside. Besides, a tuple can also be created without the using of a pair of parentheses. image

Dictionary Literals

A dictionary literal is a container used to contain a variable length sequence of Python object pairs. Elements of dictionary value can be Python objects of other types. Python object pairs in the dictionary are unordered, changeable, and not allowing duplicate members. The Python object pair of a dictionary is the key and value of the dictionary. A dictionary is enclosed by a pair of curly braces. image

Set Literals

A set literal is a container used to contain a variable length sequence of Python objects. Elements of set can be Python objects of other types. Python objects in the set are unordered, changeable, and not allowing duplicate members. Elements of a set is updated by methods of set. A set is also enclosed by a pair of curly braces. But elements of a set are single independent Python objects instead of a pair of Python objects of the form key-value pair. Beside an empty set can only be created by function set() without any argument or with no element, since empty curly braces will create an empty dictionary in Python. image
Frozenset Literals
A frozenset literal is a container used to contain a fixed length sequence of Python objects. Elements of frozenset can be Python objects of other types. Python objects in the frozenset are unordered, unchangeable, and not allowing duplicate members. A frozenset is always displayed as an immutable copy of an ordinaryl set. e.g. frozenset({85,6,7}). And a frozenset is always created by using function frozenset() to convert a collection into frozenset. image

Source and Reference


©sideway

ID: 210100006 Last Updated: 1/6/2021 Revision: 0


Latest Updated LinksValid XHTML 1.0 Transitional Valid CSS!Nu Html Checker Firefox53 Chromena IExplorerna
IMAGE

Home 5

Business

Management

HBR 3

Information

Recreation

Hobbies 8

Culture

Chinese 1097

English 339

Reference 79

Computer

Hardware 249

Software

Application 213

Digitization 32

Latex 52

Manim 205

KB 1

Numeric 19

Programming

Web 289

Unicode 504

HTML 66

CSS 65

SVG 46

ASP.NET 270

OS 429

DeskTop 7

Python 72

Knowledge

Mathematics

Formulas 8

Algebra 84

Number Theory 206

Trigonometry 31

Geometry 34

Coordinate Geometry 2

Calculus 67

Complex Analysis 21

Engineering

Tables 8

Mechanical

Mechanics 1

Rigid Bodies

Statics 92

Dynamics 37

Fluid 5

Fluid Kinematics 5

Control

Process Control 1

Acoustics 19

FiniteElement 2

Natural Sciences

Matter 1

Electric 27

Biology 1

Geography 1


Copyright © 2000-2024 Sideway . All rights reserved Disclaimers last modified on 06 September 2019