How to Build Python Data Structures

Source: Internet
Author: User

This article mainly introduces the list of Python data structures, the tuples array, the dictionary dict, the list, and the detailed introduction of the tuples and strings as sequences. The following describes the specific content of the Python data structure, I hope you will gain some benefits,

Python Data Structure

1. list: Variable Assignment Method:

 
 
  1. shoplist = ['apple', 'mango', 'carrot', 'banana'] 

2. tuples array: Variable Assignment Method:

 
 
  1. zoo = (‘wolf’, ‘elephant’,'penguin’) 

3. dictionary dict: Variable Assignment Method:

 
 
  1. d = {key1 : value1, key2 : value2 } 

4. sequence: the list, tuples, and strings are all sequences.

(1) index OPERATOR: gets a character of an element or string in the list/tuples.

(2) slice OPERATOR: gets a slice of a sequence, continuous element/Character

(3) eg:

 
 
  1. name = ’swaroop’  
  2. print ‘characters 0 is’, name[0] # ’s’  

Index operator, similar to C #

 
 
  1. print ‘characters 1 to 3 is’, name[1:3] 

'Wa 'slice operator, similar to the Substring method in C #

In fact, Python contains a lot of content. For example, Python is different from the traditional interpreted scripting language. It will be compiled into bytecode during the first execution, then run the code. NET's DLR is a bit similar to Java's virtual machine. In short, it is to convert code into a way closer to machine code, which can improve performance.

Related Article

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.