Python 2 Day--type-list-dictionary-tuples

Source: Internet
Author: User

Data types for Python:

int (integral type)

On a 32-bit machine, the number of integers is 32 bits and the value range is -2**31~2**31-1, which is -2147483648~2147483647
On a 64-bit system, the number of integers is 64 bits and the value range is -2**63~2**63-1, which is -9223372036854775808~9223372036854775807long (Long integer)
Unlike the C language, Python's long integers do not refer to the positioning width, that is, Python does not limit the size of long integer values, but in fact, because of limited machine memory, we use a long integer value can not be infinite.
Note that, since Python2.2, Python automatically converts integer data to long integers if an integer overflows, so it does not cause any serious consequences if you do not add the letter L after long integer data.
Float (float type)       First Literacy http://www.cnblogs.com/alex3714/articles/5895848.html
A floating-point number is used to process real numbers, which are numbers with decimals. Similar to the double type in C, accounting for 8 bytes (64 bits), where 52 bits represent the bottom, 11 bits represent the exponent, and the remaining one represents the symbol.
Complex (plural)
The complex number consists of real and imaginary parts, the general form is X+yj, where x is the real part of the complex, and Y is the imaginary part of the complex, where x and y are real numbers. Note: Small number pools exist in Python:-5 ~ 257 2, Boolean true or False 1 or 03, string
"Hello World"
Ternary Operations
1 result =1 if 条件 else2

If the condition is true: result = value 1
If the condition is false: result = value 2

string concatenation of all evils: the string in Python is embodied in the C language as a character array, each time you create a string, you need to open a contiguous space in memory, and once you need to modify the string, you need to open up again, the evil + sign every occurrence will re-open a space within. String Formatted output

List--arrays of C-like

Basic operation:

    • Index
    • Slice
    • Additional
    • Delete
    • Length
    • Slice
    • Cycle
    • Contains

How the list is defined:
ListName = ["ASD", 1,...]

You can also list nested lists
ListName = [1,2,3,4,[5,6,7,8,9]]

The list is also labeled with the following 0 start flag.

What the list can do:

. Append () #在末尾插入一个新的数据

Insert (x) # Inserts a data parameter x that is inserted before the data labeled X

The. Copy () # general form is ListName = Listname2.copy (), which assigns the entire copy of the list to the ListName variable (note that the shallow variable = the value of the variable is assigned, and if there is a second-level list, the memory address is passed)

Del listname # directly delete variables, after Del variables are not present

Listname.remove (x) # Deletes a function of an element in the list, and x specifies the subscript.

The list can also be assigned directly to other variables, so that the assignment is memory-assigned value. All two variables point to the same variable.

How the list is valued:
Listname[0] # takes the first underlying value

LISTNAME[-1] # takes the last underlying value

Listname[0:3] # Starting with the No. 0, take the third end, notice that the second argument is not about starting from X to fetch three data, this parameter refers to the nth of the entire list starting from 0.

Listname[-2:-3] #从-2 start Fetch, take to 3, but generally not get-3, not the end of the head.

Module copy:
Copy of the. Copy and List of the module is the same,

. Deepcopy is a deep copy.

LISTNAME[0:-1:2] # Alternative gameplay, Sweat. Starting from 0, to 1 ends, each time +2. That is to say, jump.

Python 2 Day--type-list-dictionary-tuples

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.