. Custom sort

value ： All elements in the container are compared in pairs
list01 = [54, 5, 65, 76, 87, 9] # Small --> large # Core ideas ： Using the idea of obtaining small value , Swap the minimum forward . # Access to data for
r in range(len(list01) - 1): # 0 1 2 3 4 # For comparison for c in range(r + 1,
len(list01)): # 12345 2345 345 45 5 # Find smaller if list01[r] > list01[c]: # exchange
list01[r], list01[c] = list01[c], list01[r] print(list01)
. function

Create function ：

def Function name ():

Using functions

​ Function name ()
# Code duplication is the root of all evil """ # practice ( change ) + usage print(" Straight fist ") print(" hook ") print(" Gouquan ") print(" Elbow stroke ")
# ...... # practice ( change ) + usage print(" Straight fist ") print(" hook ") print(" Gouquan ") print(" Elbow stroke ") """ #
practice ( change )1 second def attack(): print(" Straight fist ") print(" hook ") print(" Gouquan ") print(" Elbow stroke ")
print(" Forward pedaling ") # Used many times attack() attack() attack()
. parameter ： Use function to Production function Message delivered
# do # Formal parameter ： Superficial fictitious information def attack(count): for i in range(count): print(" Straight fist ")
print(" hook ") print(" Gouquan ") print(" Elbow stroke ") print(" Forward pedaling ") # Actual parameters ： Real and objective data #
debugging F8： Step by step ( Not in function ) # debugging F7： Sentence by sentence ( Enter function ) attack(1) attack(3) attack(10)
. Return value ： Making functions to transfer information to using functions
# demand ： Defining functions , Conversion of US dollar into RMB . def usd_to_cny(usd): """ Conversion of US dollar into RMB :param usd: numerical value , dollar
:return: numerical value , RMB """ cny = usd * 6.821 return cny # return result # Receive return value res =
usd_to_cny(234) print(res) # practice 1： Create a function to calculate the cure ratio # confirmed =
int(input(" Please input the number of confirmed cases :")) # cure = int(input(" Please input the number of patients cured :")) # cure_rate = cure /
confirmed * 100 # print(" The cure rate was " + str(cure_rate) + "%")
. Return value ：
def func01(): print("func01 Yes ") return 100 # Using variables a Receiving results 100 a = func01()
print(a) # 100 # Call function , You can not return a value 100 func01() def func02(): print("func02 Yes ") #
return None stay python In language , Function returns by default None func02() b = func02() print(b) # None def
func03(): print("func03 Yes ") return 300 # return You can exit the function ( Ignore the cycle )
print("func03 Again ") c = func03() print(c) # ? def func04(): print("func03 Yes ")
return # return If there is no data , The default is None d = func04() print(d) # None
. Multiple functions calling each other
# --------------- Defining functions ------------------ def single_attack(): print(" Straight fist ")
print(" hook ") print(" Gouquan ") print(" Elbow stroke ") print(" Forward pedaling ") def repeated_attack(count): for
i in range(count): single_attack() # --------------- Call function ------------------
repeated_attack(1)

Technology
Daily Recommendation
views 2