Learning Today
set
Memory-related knowledge
Copy depth
Review and supplemental content
(1) list:
(A) reverse inversion
= V1 [11,22,3111,32,13]
v1.sort (Reverse = False) # # ascending (default)
Print (V1) # output is: [. 11, 13 is, 22 is, 32, 3111]
V1 .sort (reverse = True) # # descending
Print (V1) # output result is: [3111, 32, 22, 13, 11]
(2) Dictionary
(a)keys/item/values/
(B) get: the dictionary by a key value query function similar to the default value will be returned None but when the key is not present, of course, may be designated as the default values, specific examples are as follows:
= {info 'K1': 'V1', 'K2': 'V2'}
V0 = info [ "K1"]
V00 = info.get ( "K1")
# V1 = info [ 'k11111'] will be given where
info.get = V2 ( 'k1111')
#none is empty in Python
V3 = info.get ( 'k1111', 666)
Print (V0)
Print (V00)
Print (V2)
Print (V3)
# data types #none , the type of change represents an empty (no functional, specifically for providing null)
(c)pop
= {info 'K1': 'V1', 'K2': 'V2'}
Result = info.pop ( 'K2') #resultThe return value V2
Print (info, Result) returns a value of # { "k1": "V1" V2}
# rewritable made equivalent to del info [ "k2"]
(D) update does not exist, add; update exists
info = { 'k1': ' v1', 'k2': 'v2'} # does not exist, add / presence, the update
info.update ({ 'k3': ' v3', 'k4': 'v4' , 'K2': 666})
Print (info)
# output is: { 'k1': 'v1 ', 'k2': 666, 'k3': 'v3', 'k4': 'v4'}
Whether sensitive character (e) determining a string
str
= v " Python full-stack 21 Qi "
if "全栈" in v:
print ( "contains sensitive character")
list/tuple
dict
# Allow the user to enter any string, and then determine whether or not this string contains the specified sensitive character.
char_list = [ 'Leach Air', 'bright hall', 'Fried exhibition']
Content = the INPUT ( 'Please enter content:') # I called Leach Air / I'm hall light / I want to blow up the exhibition
success = True
IF Content in char_list:
Success = False
IF Success:
Print (Content)
the else:
Print ( "contain sensitive character")
set
(1) the set of set: Characteristics: not repeated disordered
(2) a set format: V = { . 1 , 2 , . 3 , . 4 , . 5 , . 6 , 99 , 100 }
# Questions: v = {} # This is an empty dictionary
"" "
None
#int Type
V1 = 123
V1 = int () # -> 0
Print (V1)
#bool Type: bool type has only two values: True / flase
V2 = BOOL () # -> return value: flase
#str
V3 = ""
V3 = STR () # ->
#list
V4 = []
V4 = List ()
#tuple
V5 = ()
V5 = tuple ()
#dict
V6 = {}
V6 = dict ()
#set
V7 = SET ()
"" "
Unique features (3) collection
add / discard / update / intersetion (intersection) / union (union) / difference (differential current) / symmetric_differdnce
(4) public function
len (length) / for loop
# In python, integer, bool boolean, string, the tuples belonging immutable data type
# lists, dictionaries, a variable data set belonging to the type
# 1 listing, dictionaries, set -> set can not be placed + not be used as a dictionary Key (unhashable)
# info = {1,2,3,4, True, "MAK", None, (l, 2,3)}
# = {True the INFO1, 2,3,4, 1, "MAK", None, (l, 2,3)}
# Print (info)
# Print (the INFO1)
content #info output is: {1, 2, 3, 4, None, (1, 2, 3), 'MAK'}
# contents info1 output is: {True, 2, 3, 4, None, (1, 2, 3), ' MAK'}
# Note: for True is 1, Flase representatives is 0, the sets are deduplicated
# 2.hash-> hash is how is it?
## because the value will be within the hash algorithm, and obtain a value (corresponding to a memory address), is used to quickly find later.
# 3 special case
# info = {0,2,3,4, False, " MAK", None, (l, 2,3)}
# Print (info)
# result output is: {0, 'State wind ', 2,. 3,. 4, None, (. 1, 2,. 3)}
info = {. 1:' Alex ', True:' Oldboy '}
Print (info)
# outputs the result is: {1:' oldboy ' }
Memory address
Note: The two variables should be two different memory address, but there are some special circumstances.
Special case:
Exercises
v=[1,2,3]
values=[11,22,v]
#练习1:
"""
v.append(9)
print(values)
#[11,22,[1,2,3,9]]
"""
#练习2:
"""
values[2].append(999)
print(v)
#[1,2,3,999]
"""
#练习3:
"""
v=999
print(values)
#[11,22,[1,2,3]]
"""
#练习4:
"""
values[2]=666
print(v)
#[1,2,3]
"""
#练习五
# v1=[1,2]
# v2=[2,3]
# v3=[11,22,v1,v2,v1]
View memory address
V1 = # [l, 2,3]
# V1 = V2
# v1.append (999)
# Print (V1, V2)
# Print (ID (V1), ID (V2)
# output is: [1, 2, . 3, 999] [. 1, 2,. 3, 999]
# 2,938,251,599,552 2,938,251,599,552
# V1 = [l, 2,3]
# V1 = V2
# Print (V1, V2)
# Print (ID (V1), ID (V2))
# V1 = 999
# Print (V1, V2)
# Print (ID (V1), ID (V2))
# output is: [1, 2, 3] [1, 2, 3]
# 2278782156608 2278782156608
# 999 [1 , 2, 3]
# 2278782223248 2278782156608
Question: == and is there any difference?
to sum up
List: reverse / sort
Dictionary: find / pop / update
集合:add/discard/update/intersection/union/difference/symmetric_difference
Special: Nested: set / dictionary Key; empty: None, empty set. . . .
id
type
Nested Application: assignment, modify the internal elements: a list / dictionary / collection