程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python built in function

編輯:Python

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 )


keyword :

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

class: Defining classes


as: For type conversion

raise: Exception throw operation
try: For exception statements
except: For exception statements
finally: For exception statements

Built in functions : Consistent with the call of the defined function


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

Common methods : String method


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

List common methods : It can store all kinds of data types


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


Methods of adding, deleting, looking up and modifying dictionaries

# 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)

Several other methods commonly used in dictionaries


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

Method : Use of methods : object . Method name ( Parameters )


for example : List method
li = [11,22,33]
li.append()

'''
```


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved