MindMap Gallery Python data types
Python Basics - Data types, these data types are very common in Python programming, and each type has its specific methods and operations that can facilitate data processing.
Edited at 2024-03-14 17:00:25This is a mind map about bacteria, and its main contents include: overview, morphology, types, structure, reproduction, distribution, application, and expansion. The summary is comprehensive and meticulous, suitable as review materials.
This is a mind map about plant asexual reproduction, and its main contents include: concept, spore reproduction, vegetative reproduction, tissue culture, and buds. The summary is comprehensive and meticulous, suitable as review materials.
This is a mind map about the reproductive development of animals, and its main contents include: insects, frogs, birds, sexual reproduction, and asexual reproduction. The summary is comprehensive and meticulous, suitable as review materials.
This is a mind map about bacteria, and its main contents include: overview, morphology, types, structure, reproduction, distribution, application, and expansion. The summary is comprehensive and meticulous, suitable as review materials.
This is a mind map about plant asexual reproduction, and its main contents include: concept, spore reproduction, vegetative reproduction, tissue culture, and buds. The summary is comprehensive and meticulous, suitable as review materials.
This is a mind map about the reproductive development of animals, and its main contents include: insects, frogs, birds, sexual reproduction, and asexual reproduction. The summary is comprehensive and meticulous, suitable as review materials.
Python data types
numerical value
type
integer
int
base
binary
0b
0B
Octal
0o
0O
decimal
hexadecimal
0x
0X
floating point number
decimal
float
Don't do calculations
Conversion to binary is biased
There is a value range
maximum value
1.7976931348623157e 308
inf
minimum value
2.2250738585072014e-308
0.0
plural type
Imaginary numbers are represented by j
Example
c=4 5j
value
Show real part
c. real
Show imaginary part
c.imag
Model length
abs(c)
Boolean type
bool
Number to Boolean type
False
0
0.0
null
True
any other value
The first letter must be capitalized
value
True
1
False
0
Can be converted to a number using int()
You can directly participate in digital operations after assignment
Operation
and
All T
T
There is F
F
short circuit
When it is judged that there is F
stop running
ReturnF
Example
All T
last value
There is F
first F
or
All F
F
There is T
T
short circuit
When it is judged that there is T
stop running
Return T
Example
All F
last value
There is T
first T
Operation
Addition, subtraction, multiplication and division
power
**
Rounding
//
Take the remainder
%
equal
==
not equal to
! =
sequence
type
immutable types
string
str
create
apostrophe
Double quotes
triple quotes
newline
apostrophe
line continuation character
\
Newline input
Peer display
end of first line
newline character
Newline input
Line wrap display
Beginning of second line
Used with line continuation character
triple quotes
Line break directly
Line wrap display
Operation
.join()
Splicing
Example
s.join(["a","b","c"])
Use s to splice "a" "b" "c"
.replace()
replace
Example
s.replace(old,new,1)
Replace old with new
old/new should both be strings
bring''
Replace all by default
.split()
Cut with content in brackets
no parameters
Cut with spaces
Results are stored in list form
.strip
cut
Commonly used to remove spaces on both sides
tuple
structure
tuple
read-only list
subtopic
( )
create
t1 = ()
t2 = tuple()
t3 = tuple((1,2,3))
t4 = (1,2,3)
when an element
add comma
t5=(1,)
element
Multiple data types available
integer
floating point number
string
list
tuple
…
Repeatable
In order
Unchangeable
If the elements in the tuple are mutable elements
The elements in a mutable element can be modified
mutable type
list
Format
list
[ ]
create
l1=list()
l1=[]
element
Multiple data types available
integer
floating point number
string
list
tuple
…
Repeatable
In order
function
Add to
.append(x)
Add x
end of list
.insert(index,object)
Insert at specified position
index
insertion position
object
insert element
l1.extend(l2)
merge
Merge l2 elements to the end of l1
delete
.pop(index)
Delete the element at the specified position
Return the content after deleting the element
.remove(object)
Delete specified content
object
element to delete
Delete only the first one
.clear()
Clear all elements
use
Delete all specified elements in the list
Delete directly
Import other elements into new list
list comprehension
sort
Reverse order
.reverse()
rearrange
Ascending order
.sort()
.sort (reverse=False)
descending order
.sort (reverse=True)
copy
direct assignment
Alias
The value address remains unchanged
Shallow copy
copy
parent object
Do not copy child objects
Only create a first-level list
First layer address change
Subsequent addresses remain unchanged
value
sublist
…
deep copy
deepcopy
full copy
All addresses changed
function
length
len()
Spaces and punctuation all count as length
index
Format
String name[index]
scope
-len() ——len()-1
index
first character on the left
0
A positive number
from left to right
negative number
right to left
Can also be used for lists etc.
slice
Format
String name [start:end:step]
Close in front and open in back
start
start character
available
Omit
first character from left
end
End of value
Can't get it
Omit
Get the last character
step
Step
Take one for every few characters
A positive number
Take values from left to right
negative number
Take values from right to left
Omit
1
Same operation
merge
*
Repeat n times
in not in
judge
Whether included in the string
return
True
False
==
judge
equal
is, is not
Compare
Whether the object (memory address) is the same
id(object)
object memory address
only
.index()
Returns the position of the first occurrence of the substring
Example
s.index("o",5)
The first occurrence of substring "o" after position 5 in string s
The number of occurrences of a given element
l1.count(x)
The number of times x appears in l1
gather
set
mutable type
Features
certainty
The element is an immutable data type
Cannot contain lists
Mutuality
Elements cannot be repeated
Automatically remove duplicates
Convert a list to a collection and then convert it back to a list
disorder
no order
Not indexable
s[index]
mistake
Traverse
Default from smallest to largest
set derivation
{output value for i in set}
{i 2 for i in s}
create
s = set()
s = {element}
{} Created as a dictionary when there is no content
subtopic
function
Add to
.add
Add customized elements
Duplicate values are not added
delete
.pop()
Randomly delete
.remove()
Delete specified value
Clear
.clear()
intersection
.intersection(set)
s1.intersection(s2)
The intersection of s1 and s2
&
union
.union()
s1.union(s2)
|
s1|s2
difference set
.difference()
Remove the elements of the set in parentheses from the set, and the remaining part
s1 = {1,2,3,4} s2 = {3,4,5,6} s1.difference(s2)
{1,2}
Symmetric difference set
The union of two sets removes the handover, and the remaining part
.symmetric_difference()
s1 = {1,2,3,4} s2 = {3,4,5,6} s1.symmetric_difference(s2)
{1,2,5,6}
^
s1 = {1,2,3,4} s2 = {3,4,5,6} s1^s2
{1,2,5,6}
insinuation
dictionary
dict
element
key value pair
key:value
key
key
value
value
A key-value pair is an element
a length
key cannot be repeated
immutable types
Not listable
value can be repeated
No restrictions on data types
disorder
Key-value pairs are unordered
create
dict()
{}
{key: value}
function
Add to
Assignment
d[key]=
key exists
Revise
key does not exist
Add to
.setdefault(key:value)
Value does not need to be written
Default is None
Inquire
[key]
key exists
return value
key does not exist
Report an error
.get(key)
key exists
return value
key does not exist
No error reported
.get(key,'prompt')
key exists
return value
key does not exist
Return prompt
delete
.pop(key)
Delete the specified key-value pair based on key
.popitem()
Randomly delete
Clear
.clear()
Traverse
.keys()
All keys
.values()
all values
.items()
All key-value pairs
tuple form
dict_items([(key1,value1),(key2,value2),…])
for in
key
for i in d: print(i)
for k in d.keys(): print(k)
for item in d.items(): print(item[0])
for k,v in d.items(): print(k)
value
for v in d.values(): print(v)
for item in d.items(): print(item[1])
for k,v in d.items(): print(v)
item
for item in d.items(): print(item)
multiple tuples
key value
for k,v in d.items(): print(k,v)
dictionary comprehension
{k:v for k,v in d.items() if v >60}