Python built-in data type details, python Data Type Details

Source: Internet
Author: User

Python built-in data type details, python Data Type Details

Generally, Python is positioned as a scripting language-scripting language high-level dynamic programming language.

Python is dominated by data, and variable value change refers to a variable pointing to an address.
That is, Id (variable)-> display the address of the variable.
Therefore, a specific value has different variable names.

Python data type:

Numbers, strings, lists, tuples, and dictionaries
Numbers and strings are actually very basic data types, which are not very different from other languages in Python. I will not elaborate on them here.

Dictionary introduction:

Dictionary is one of Python's built-in data types. It defines the one-to-one relationship between keys and values.
It is actually a hash array.
Simple definition of Dictionary: Dic = {'key1': 'value1', 'key2': 'value2 '}
A Dictionary cannot contain duplicate keys. assigning values to the same Key overwrites the original values.
You can add a Key-Value pair to the Dictionary at any time.
There is no element order in Dictionary! There is no order for finding the Value through the Key.
In Dictionary, the Key is case sensitive!
Dictionary is not just used to store strings. The value of a Dictionary can be of any data type, including the Dictionary itself. At the same time, in a single Dictionary, the values of the Dictionary do not need to all be of the same data type and can be mixed and matched. The data type of a Dictionary Key has relative requirements, but it can be mixed and matched by multiple data types.
Del can use a Key to delete the corresponding element in the Dictionary. >>> Del dic [12]
Clear () can delete all values in a Dictionary, but the original Dictionary is still there, but it becomes null {}. >>> dic. clear ()

List introduction:

List is the most frequently used data type in Python.
The data types in the List can be arbitrary and dynamic expansion is supported.
Simple definition of List: Lis = ['A', 'B', 'abc', 'asd ']. List is a set of ordered elements enclosed by square brackets.
List supports two index modes: normal index mode, starting from 0.
Negative indexes are counted from the end of the List. The last original of any non-empty List is always List [-1].
List supports sharding, which is used to retrieve data from the List. Note the starting position of Slice.
Add data to the List: Lis. Append ('new') add data to the end of the List;
Lis. insert (2, 'new') inserts a value at the position of List 2;
Lis. extend (['new', 'nwe']) links to a New List (at the end) in the original List ).

Differences between Append () and Extend:

①. The Append () parameter can be of any data type, but it can also be a List, but it adds how to List as an element to the original List.
② The parameter of Extend () can only be a List, and all the elements of the entire List are added to the original List one by one.
③. Search in List: Lis. index ('A ')
④. Index searches for a value in the List and returns its first index value. If it appears multiple times, only the first index value is returned. If it is not in the List, an exception is returned.
⑤ Test whether a value is In the List. The value returned by 'in :>>> 'C' in lis is False.

Delete an element from the List:

①. Lis. remove ('A') first appearance of deleting a value from the List (not all ).
②. Lis. pop () will do two things: Delete the last element of the List and return the deleted element.
③. List can be linked using the + operator. List = List + otherList is equivalent to list. extend (otherList ). However, the + operator uses a new list (after link) as the return value, while extend () only modifies the existing List. Therefore, for large lists, the execution speed of Extend () is faster.
④ List supports the + = Operator.
⑤ The * operator in the List can act on the List as a repeat. Lis = [1, 2] * 3 is equivalent to lis = [1, 2] + [1, 2] +. That is, link the three lists into one.

Tuple introduction:

Tuple is an unchangeable List. Once a Tuple is created, it cannot be changed in any way.
Simple definition of Tuple: Tup = ('A', 'B', 'abc', 'asd ') the entire element set is surrounded by parentheses.
Because Tuple is immutable, there is no way to add or delete elements. You can partition indexes in the same way as List indexes. When a List is split, a new List is obtained. When a Tuple is split, a new Tuple is obtained.
Tuple can also use the in method to check whether an element exists in Tuple.

Tuple can be considered as a special List, which has the following advantages:

①. Tuple is faster than List operations. To define a constant set, you only need to use Tuple for storage. Your unique operation on it is to continuously traverse it.
②. Tuple can be seen as "Write protection" for data that does not need to be changed ". This makes the code more secure.
③. Tuple can be used as the Key in Dictionary, but the List cannot! Because the key in Dictionary must be unchangeable.
④. Tuple can be converted to List. The built-in tuple function can receive a List and return a Tupelo with the same elements. The List function receives a Tuple and returns a List.

An in-depth understanding of the Python built-in data types described in this article will be of great help for mastering Python program design.

Python Data Type

CS is a reference.
The difference between reference and pointer should be clear: the former is the memory alias, and the latter is the storage variable of the memory address.
CS is a reference. To return the C language, you must use pointer variables instead of pointer variables.
The pointer should accept id (CS ).
* The pointer accepts cs.

Appendix: actual operation of the ID function
>>> Cd
>>> Id (cd)

Beginner in python Data Type

This has nothing to do with the xlrd module. The xlrd module should not have the get_Excel_value_S function, which should be defined by you and the returned data type is float, if you do not want to use data conversion, there are two solutions.
1. Write a function that returns an integer.
2. Confirm the table corresponding to this array and obtain this value through the cell in xlrd, such as xxx = table. cell (0, 0 ). value. Two zeros indicate the number of rows and the number of columns respectively.

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: 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.