Python Jobs (data type Cont.)

Source: Internet
Author: User

Data type (cont.)

1 List

Definition: [] separated by commas, by index, storing various data types, each position represents an element

Characteristics

1 can hold multiple values

2 can modify the corresponding value of the index position, variable

3 list elements are defined in left-to-right order, subscript is accessed sequentially from 0, ordered

1 list_test[' LHF, ' k, ' OK ']2 or 3 list-test=list (' abc ') 4 or 5 list_test=list ([' LHF ', ' + ', ' OK '])

List common actions

Index

Slice

Additional

Delete

Length

Slice

Cycle

Contains

2 tuples

Definition: Similar to a list, except [] Change to ()

Features: 1 can hold a value of 2 immutable 3 The tuple element is defined in the order from sitting to right, the subscript is accessed sequentially from 0, ordered

Tuple creation

1 age= (11,22,33,44,55) 2 or 3 ages=tuple ((11,22,33,44,55))

Tuples Common operations

Index

Slice

Cycle

Length

Contains

3 Dictionaries

Definition: (key:value1,key2:value2), key-value structure, key must be hash

Attribute 1 can hold multiple values 2 can modify the value corresponding to the specified key, can be changed to 3 unordered

Dictionary creation

person={' name ': ' SB ', ' Age ': 18} or Person=dict (name= ' SB ', age=18) person=dict (name= ' SB ', age=18) person=dict ([' Name ', ' SB '],[' age ',] {}.fromkeys (seq,100) #不指定100 default to None Note "Dic={}.fromkeys ([' K1 ', ' K2 '],[])" dic{' K1 ': [1], ' K2 ': [1] }

Dictionary common Operations

Index

New

Delete

Key, value, key-value pairs

Length

4 Collection

Definition: A collection of different elements, a set of unordered permutations of hasha values that can be used as a dictionary key

Characteristics:

1 The purpose of the collection is to store different values together between different sets for relational operations, without having to tangle the individual values in the set

Creation of collections

{1,2,3,1}

Or

Define a mutable collection set

>>>set_test=set (' Hello ')

>>>set_test

Frozenset ({' 1 ', ' 2 ', ' h ', ' O '})

Collection common operations: relational operations

Inch

Not in

==

!=

<,<=

>,>=

|,|=: The collection

&.&=: Intersection

-,-=: Difference Set

^,^=: Symmetric difference Set

Python Jobs (data type Cont.)

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.