Python-07:python Syntax Basics-Data types

Source: Internet
Author: User

1. Basic Data type

2. List

  There are no arrays in Python!!! And the arrays are similar to lists and tuples.

  A list is a container for storing a chain of elements. To be represented by [], arranged in an orderly manner.

3, meta-group

The elements inside the tuple are also available for index calculation.

The difference between a tuple and a list:

The value of the element in the ① list can be modified, but the value of the element inside the tuple is not modifiable.

The symbol for the ② list is [], and the tuple's symbol is ()

  

4. Collection

The collection in Python has two functions, one is to build relationships, and the other is to eliminate duplicate elements (principle: The elements in the collection are unique, and the elements in the string are not unique, and the result is heavy after the string set)

The format of the collection is: Set (Element)

#Encoding:utf-8A=set ("Abcnmaaaaggsng") b=set ("CDFM")#intersectionx=a&b#and sety=a|b#Difference Setz=a-b#Remove duplicate elementsnew=set (a)Print "The intersection is: {0}\n is set to: {1}\n difference set is: {2}\na after removing duplicate elements: {3}". Format (x,y,z,new)

The output result is

The intersection is: Set (['C','m']) and set as: Set (['a','C','b','D','g','F','m','N','s']) Difference set is: set (['a','s','b','g','N'] A after removing the repeating element: set (['a','C','b','g','m','s','N'])

5. Dictionaries

The dictionary in Python is an associative array, enclosed in curly braces {}.

# encoding:utf-8score={" Chinese ": "A ", " mathematics ": English ": 2}score[" computer graphics "]=69 for" Score:    print"{0} has a score of: {1}". Format (Key,score[key])

The output is:

The results of the mathematics are: the results of the Chinese language: The results of the English: 2 Computer graphics:69

Python-07:python Syntax Basics-Data types

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.