There are six standard data types in the Python3:
First, all data types can be judged using type or isinstance.
For example, type (2.3) type (TRUE) returns a value of int float and bool
Isinstance (x, y) verifies that x is the Y type if True returns True for false and vice versa
Number (numeric)
It contains int shaping float float Complex complex bool Boolean in Python 3, with only one integer type int, expressed as a long integer, and no python2.
The type is immutable
Most of its operations are in the same way that other languages need to be noted:
A/b represents a/b floating point value
A//b on behalf of A/b take the whole number of parts
A**b represents the B-order of a.
String (String)
The strings in Python are enclosed in single quotation marks (') or double quotation marks ("), while the backslash (\) is used to escape special characters while the elements of the string are not modifiable.
His format is usually str = "123ABC" or str = ' 123ABC '
The plus sign (+) is the list join operator, and the asterisk (*) is a repeating operation
The escape character is typically used in an expression where the print(' NB ') output is originally NB but if print (' \NB ') is wrapped, the output b
If you do not want to escape character use then add R such as print (R ' \nb ') when using the output is NB
In addition, the backslash (\) can be used as a continuation character, indicating that the next line is the last row of continuations
The common operations of strings and lists and tuples are slices str[head node, tail node, step size] When not written, the default head node is the first tail node as the last step is 1 and its value can be negative
list (lists)
The list is a bit like an array, but his type is list and it can do most of the data structures.
Its format is usually list = [' 123 ', 123, ' ADBC ']
The plus sign (+) is the list join operator, and the asterisk (*) is a repeating operation
The common operations of strings and lists and tuples are slices str[head node, tail node, step size] When not written, the default head node is the first tail node as the last step is 1 and its value can be negative
Tuple (tuple)
Tuple (tuple) is similar to a list, except that the elements of a tuple cannot be modified. Tuples are written in parentheses (()), and the elements are separated by commas.
Its format is usually tuple = (123, 456, ' abc ') but when it is empty tuple = () when he has only one element when tuple = (1,)
The plus sign (+) is the list join operator, and the asterisk (*) is a repeating operation
The common operations of strings and lists and tuples are slices str[head node, tail node, step size] When not written, the default head node is the first tail node as the last step is 1 and its value can be negative
Although the elements of a tuple cannot be changed, it can contain mutable objects, such as list lists.
String, list, and tuple all belong to sequence (sequence)
Dictionary (dictionary)
A dictionary is similar to a collection of maps in other languages, and a dictionary is an unordered collection of objects. The difference between the two is that the elements in the dictionary are accessed by keys, not by offsets.
A dictionary is a type of mapping that is identified by the dictionary with "{}", which is an unordered key (key): The value pair collection. The key (key) must use the immutable type. In the same dictionary, the key must be unique.
His format is usually dic = {' 123 ': 123123, at: ' abc '} Empty dict = {}
It is also possible to use the Dict keyword DIC = dict.dict (("Wanger", 23), ("11", 22)) so that the sequence is produced or is dic = Dict.fromkeys (["123", 123], 333) to all keys Give a unified value
Sets (collection)
A collection (set) is a sequence of unordered, non-repeating elements, and the basic function is to test the membership and remove duplicate elements.
You can create a collection using the curly braces {} or the set () function, note: Creating an empty collection must be set () instead of {}, because {} is used to create an empty dictionary.
His format is sets = {1, 2, "abc"} or set = (123)
Set set can be used for a bit of arithmetic
print (a- Span class= "Hl-identifier" >b) # Difference set for A and B
Span class= "Hl-identifier" >print (a | b) # A and B in the same set
< Span class= "hl-brackets" > print ( A & b Span class= intersection of "Hl-comment" ># A and b
print (a ^ b) # A and B elements that do not exist simultaneously
immutable Type: variable assignment a=5 and then assign value a=10, here is actually reborn into an int value object 10, then a point to it, and 5 is discarded, not change the value of a, the equivalent of a new student into a.
Variable type: variable assignment la=[1,2,3,4] after assigning a value la[2]=5 is to change the value of the third element of List LA, itself LA is not moving, but its internal part of the value has been modified.
Data types for Python