Python data type

Source: Internet
Author: User

Data type: list, tuple, collection, dictionary

#列表 (indicated in brackets)

students=[" Xiao Ming", "Xiao Hong", " Xiaoice", "Xiao Yue"," little White"]

Print students[3]

Students[3]= " Lei Feng". # # Change The value of 3

Print students[3]

#元组

Students= ("Xiao Ming", "Xiao Hong", "Xiaoice", "Xiao Yue", "Xiao Bai")

Print students[1]

The difference between a list and a tuple

1, the value of the elements of the list can be modified, and the value of the elements inside the tuple cannot be modified to read only

2, the symbol of the list is [], and the tuple's symbol is ().

#集合

Function

1. Establishing a relationship

2. Eliminate duplicate elements

The format of the collection is:set (Element)

Cases:

A=set("ABCDEFG")

B=set("CDFM")

#交集

X=a&b

Print X

#并集

Y=a|b

#差集

Z=a-b

#去重复元素

New=set(a) # Remove duplicate values of a

#字典

Also called associative array, enclosed in curly braces {}.

zidian={' name':' xiaoming', ' Home':' Shenzhen ', ' like':' music'}

In fact, the dictionary contains a whole thing, each has specific information, such as the name,home, likethe values are xiaoming,Shenzhen,Music, elements separated by commas

Cases:

k={"name": " xiaoming", "Home": " Shenzhen"}

Print k["name"]

#添加字典里面的项目

k["like"]= "Music"

Print k["Name"]

Print k["Like"]

Python data type

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.