Python's core data structure

Source: Internet
Author: User

Data Example
Digital 1234,3.1415,3+4j
String ' Spam '. " Grace ' s "
List [1,[2, ' three '],4]
Dictionary {' food ': ' spam ', ' taste ': ' Yum '}
Meta-group (1, ' spam ', +, ' AB ')
File File = open (' Eggs ', ' r ')
Collection Set (' abc '), {' A ', ' B ', ' C '}

Other types

None, type Boolean

Digital

Number type:

    1. integers: integers with no fractional parts
    2. Floating-point number: Numbers with a decimal part behind it
    3. Other: decimal number with imaginary part, fixed precision, rational fraction with numerator and denominator, set

String

 Single quote ' and double quotation mark ' to create a string

var1 = "Double quotation mark"

VAR2 = ' single quote '

List

The most common sequence in Python is the list object. A list is an ordered collection of positions related to an arbitrary type of object, with no fixed size. Similar to arrays in Java, but more powerful than arrays. The list can include integers, strings, floating-point numbers, and even lists. Example: L = [123, ' spam ', 12.34, [n/A]]

List = [element 1, Element 2, ...]

Dictionary

  A dictionary in Python is a mapping (mapping), which is stored by key, and the key is mapped to a value. A dictionary is the only data structure in Python that has a type of mapping. As with lists, dictionaries are also variable and can be enlarged or reduced.

Dictionary = {Key 1: value 1, key 1: Value 2}

Meta-group

Tuples are like immutable lists, with immutability. Because of his immutability, tuples provide an integrity constraint that is often used to write larger programs.

 Tuple = (element 1, Element 2)

File

  The file object is the primary interface for external files on your computer in Python code. However, there is no specific common syntax for creating files in Python. To create a file object, you need to call the built-in open function as a string to give it an external file name and a string to handle the pattern.

 File = open (' Data.txt ', ' W ')

Python's core data structure

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.