1, number -> Int class
Of course, for numbers, Python's number types are int integer, long integer, float floating point number, complex number and Boolean value (0 and 1). Only int integers are introduced and studied here.
In Python2, the size of integer is limited, that is, when the number exceeds a certain range, it is no longer an int type, but a long integer. In Python3, no matter the size or length of an integer, it is called integer int.
There are two main methods:
int->; Converts the data type of a string to int type. Note: The contents of the string must be numbers.
bitlength()-& gt; Converts a number to a binary number and returns the number of digits of the smallest binary number.
2. Boolean value-> Boolean class
For Boolean values, there are only two results, namely true and false, which correspond to binary 0 and 1 respectively. There are too many values of True and true. We just need to know what the values of Flase and true are-"none, empty (that is, []/()/{}), 0;
Related recommendation: python video tutorial
3. string-> string class
String is the most commonly used data type in Python, and it has many uses. We can use single quotation marks'' or double quotation marks'' to create strings.
The string cannot be modified. We can introduce all the characters from the aspects of index, slice, length, traversal, deletion, segmentation, blank space, case conversion, and judging where to start.
Create string
slice up
Index->; index()、find()
The difference between index () and find () is that if the character or sequence of the index is not in the string, the value of index-- > is wrong: no substring is found, but for find-- >; Returns-1.
Length->; len()
Note: len () method-> It can also be used for other data types, such as viewing the number of elements in lists, tuples and dictionaries.
Delete-> nabla
Judging the contents of a string-> isalnum()、isalpha()、isdigit()
Case conversion->; Uppercase (), lowercase (), uppercase (), title (), casefold ()
Judge what starts and ends-> startswith()、endswith()
Expand-> expandtabs()
Print format-> format()、format_map()
method of attachment
Split-> Split (), split ()
Replace->; replace
Replace-> Makestran, translation
4. list-> list class
A list consists of a series of elements, with specific elements arranged in order. Its elements can be any data type, that is, numbers, strings, lists, tuples, dictionaries, Boolean values, etc. Their elements can also be modified.
Its form is:
Names = ['little-five ","James ","Alex "] 2 # or 3 names = list (['little-five ","James ","Alex "])
Index, slice
Add-> Add ()
Expand-> Extension ()
Note: the difference between extending extend and appending append:-> The former is to add elements as a whole, and the latter is to decompose elements of data type into a list. Example:
insert()-& gt; insert
pop()-& gt; take out
remove()-& gt; Delete, del-& gt;; delete
sorted()-& gt; Sorting, the default positive order, plus reverse =True, means reverse order.
5. tuple->; Tuple class
A tuple is a list that cannot be modified. Its characteristics are similar to list. They are identified by parentheses instead of square brackets.
# tuple name = ("Xiaowu", "Xiaowu") print (name [0])
6. dictionary > dictionary class
A dictionary is a series of key-value pairs. Each key-value pair is separated by a comma, and each key corresponds to a value. You can use the key to access the corresponding value. Disorder.
The definition of a key must be immutable, that is, it can be a number, a string, a tuple, a Boolean value, etc.
The definition of a value can be any data type.
Ergodic->; Items, keys, values
7. Settings-> Set category
Definition of a set: In my opinion, a set is like a basket. You can put things in it or take things from it, but these things are out of order, so it is difficult for you to specify to take one thing alone. At the same time, you can filter through certain methods to get what you need. Therefore, collections can be created, added, deleted and related operations.
Features of this kit:
1, deduplication
2. Chaos
3. Each element must be an immutable type (hashable type, which can be used as the key of dictionary).
Creating: sets, frozen sets
Add: to add, update
Delete: eject, remove and discard.
Relational operation: intersection &; , union set |, difference set-,complement set, issubset, isupperset.
Judge whether the relationship between two sets is a subset or a parent set->; issubset、isupperset