Catalog
keyword :
class: Defining classes
Built in functions : Consistent with the call of the defined function
Common methods : String method
List common methods : It can store all kinds of data types
Methods of adding, deleting, looking up and modifying dictionaries
Several other methods commonly used in dictionaries
Method : Use of methods : object . Method name ( Parameters )
False:bool data type
True:bool data type
None: Indicates that the content of the data is empty
and: Logical operators : And
or: Logical operators : or
not: Logical operators : Not
in: Identity operator , Determine whether the variable is in the sequence
is : member operator , Determine whether the variable is an instance of a class
del: Delete the value of a variable or sequence
assert: Sort the list , The default order is from small to large , Ascending , Add parameters reverse=True, Sort in descending order
with: simplify Python The sentence of
pass: Said by ( Usually used to occupy space )
if elif else: conditional
while: Conditional statements
for: Loop statement
break: End cycle , Jump out of the loop
continue: Terminate the current cycle , Start the next cycle
def: Keywords defined by the function
return: Define the function to return the calculation result , To receive
global: Define global variables
nonlocal: Modify the value of the local variable of the external function inside the nested function
lambda: Defining anonymous functions
yield: Used to return values from a function in turn
import: Define modules
from: For importing modules , And import Use a combination of
as: For type conversion
raise: Exception throw operation
try: For exception statements
except: For exception statements
finally: For exception statements
print : Output
input : Input
type : View data type
id : Get the memory address of the data
range : Generate the data
len : Get the length of the data ( The total number of elements )
int、float 、bool 、str、list、tuple、dict、set: Represents the corresponding data type
eval: Identify... In a string python expression
eval: You can convert string types to lists or primitives
join String splicing , Convert list to string
find Find element location
count Find the number of elements
replace Replace character
split String segmentation , Convert string to list
format Format output The traditional way :%
upper Capitalize the letters
lower Put the letters in lowercase
Variable data type , The most used data storage methods
Take value by subscript , List method
increase :
append Add data to the list ( At the end of )
insert Insert data through the specified location
extend You can add multiple pieces of data to the list at one time ( At the end of )
Delete :
remove Delete the element specified in the list
pop Specify the subscript position to delete , Delete the last element of the list by default
clear clear list
del Keyword deletion , Specifies that the subscript is deleted , Method can be deleted
Inquire about :
index Subscript method of query list
count Get the number of elements
Be careful : The query method needs variables to receive
modify : Find the corresponding element through the subscript position and modify it
li3[5],li3[6] = 111,222
other :
copy Copy list
sort Sort , The default order is from small to large , Ascending , Add parameters reverse=True, Sort in descending order
reverse Reverse the list
# Add elements to the dictionary
# Assignment by key dic[key] = value
dic["age"] = 18
print(dic)
# Modify elements in the dictionary ( In the dictionary key Is the only one. , Can't repeat ),
dic["age"] = 188
# summary : Dictionaries add and modify elements , nothing key Then increase , If there is one, change it
# Look up elements in the dictionary
# Use the key to find the corresponding value ( When the key you are looking for does not exist , Will report a mistake )
n = dic["name"]
print(n)
# The second kind :dic.get(key)( When the key you are looking for does not exist , The return is None)
n = dic.get('name')
print(n)
# Delete element from Dictionary
dic1 = {'aa':11,'bb':22,'cc':33}
# pop Method : Specify the key to delete the key value pair
print(dic1.pop("aa"))
print(dic1)
# popitem: Delete the last key value pair in the dictionary (python3.6 Start )
dic1.popitem()
print(dic1)
# del keyword To delete
del dic1['bb']
print(dic1)
dic2 = {'aa': 11, 'bb': 22, 'cc': 33}
# keys: Get all keys
print(list(dic2.keys()))
# values: Get all values
print(list(dic2.values()))
# items: Get all key value pairs , Each key value pair is a primitive form
print(list(dic2.items()))
# How to combine two dictionaries :update,dic1 Update to dic3 Go inside
dic3.update(dic1)
print(dic3)
# Add multiple key value pairs to the dictionary
dic3.update({"ff": 11, "dd": 99})
print(dic3)
# How to combine two dictionaries :update,dic1 Update to dic3 Go inside
dic3.update(dic1)
print(dic3)
# Add multiple key value pairs to the dictionary
dic3.update({"ff": 11, "dd": 99})
print(dic3)
function 、 keyword 、 Differences in the use of methods
function :
The function is : Function name ()
print("hello python")
input(" account number ")
keyword
Keyword use : Keyword name python expression ( There are no brackets )
del li[0]
if Conditional statements
return a+b
for example : List method
li = [11,22,33]
li.append()
'''
```