This article is 【Python Language foundation 】 Column articles , Mainly the notes and exercises in class
Python special column Portal
The experimental source code has been in Github Arrangement
Use two methods to merge data from two lists
List together , You can use + Number or extend() Method
""" @Author: Zhang Shier @Date:2022 year 05 month 18 Japan @CSDN: Zhang Shier @Blog:zhangshier.vip """
leaders_1 = [ 1, 2 ]
leaders_2 = [ 3, 4 ]
full_leaders_list = leaders_1 + leaders_2
print ( full_leaders_list )
leaders_1.extend ( leaders_2 )
print ( leaders_1 )
set1={2,5,9,1,3},set2={3,6,8,2,5}, Call the set operator or function to complete the following functions :
Use add()
Method to add new elements , Using set operators | 、& 、- , Do the intersection operation ,item in set
Judge keywords
""" @Author: Zhang Shier @Date:2022 year 05 month 18 Japan @CSDN: Zhang Shier @Blog:zhangshier.vip """
set1 = {
2, 5, 9, 1, 3}
set2 = {
3, 6, 8, 2, 5}
set1.add ( 7 )
print ( " Additive elements 7 The set after is :", set1 )
print ( " aggregate set1 and set2 The union of is :", set1 | set2 )
print ( " aggregate set1 and set2 The intersection of is :", set1 & set2 )
print ( " aggregate set1 and set2 The difference set of is :", set1 - set2 )
print ( " keyword key = 4 Is in collection :", (4 in set1) or (4 in set2) )
Will be a class of students 《Python Programming 》 The results of this course are kept in a dictionary , The student number is the key (key), The score is a value (value). Achieve the following functions :
Use built-in functions directly
Delete list.pop()
Inquire about list.get()
The highest max(list.valuse())
Lowest score min(list.valuse())
average max(list.valuse())/len(score)
""" @Author: Zhang Shier @Date:2022 year 05 month 18 Japan @CSDN: Zhang Shier @Blog:zhangshier.vip """
score = {
'001': 96, '002': 98, '003': 92, '004': 93, '005': 94}
print ( " The initial student grade is :", score )
score[ '006' ] = 100 # add to
print ( " Add... To the dictionary 006 Student No. 1 scored :", score )
m_num = input ( " Student ID of the student who modified the grade " )
m_score = int ( input ( " It is amended as follows " ) )
score[ m_num ] = m_score # modify
print ( " After revising the students' grades in the dictionary :", score )
delete = input ( " Enter and delete student id " )
score.pop ( delete ) # Delete
print ( " After deleting student grades :", score )
query = input ( " Enter the student number of the query student " )
print ( " The number is %s The score of is : %d "%(query, score.get ( query )) ) # Inquire about
print ( " The highest score is :", max ( score.values () ) )
print ( " The lowest score is :", min ( score.values () ) )
print ( " The average is divided into :", sum ( score.values () )/len ( score ) )