TOCPython LiteralString LiteralBytes LiteralInteger, Floating Point Number, Imaginary LiteralsBoolean, None Literals Draft for Information Only
ContentPython Collection Literal
Python Collection LiteralBesides, 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 LiteralLiteralElementArrangementMutabilityDuplicate Member ExampleList LiteralsA 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 commasTuple LiteralsA 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 commasDictionary LiteralsA 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.Set LiteralsA 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.Frozenset LiteralsA 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.Source and Reference
©sideway ID: 210100006 Last Updated: 1/6/2021 Revision: 0 Latest Updated Links
|
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 Set 1 Logic 1 Algebra 84 Number Theory 206 Trigonometry 31 Geometry 34 Calculus 67 Engineering Tables 8 Mechanical Rigid Bodies Statics 92 Dynamics 37 Fluid 5 Control Acoustics 19 Natural Sciences Matter 1 Electric 27 Biology 1 |
Copyright © 2000-2024 Sideway . All rights reserved Disclaimers last modified on 06 September 2019