All operations python dictionary

Dictionary creation # 
# dict1} = {
# Print (type (dict1))
#
# dict2 = {
# 'name': 'Feng Wang',
# 'Sex': 'M',
# 'HireDate': '1997-10- 20 is '
#}
# Print (dict2)
#
# dict3 = dict (name =' Eric ', Age = 28)
# Print (dict3)

# operation value
# = {Employee
#' name ':' Feng Wang ',
#' Sex ':' M ',
#' Grade ':' A ',
#' HireDate ':' 1997-10-20 ',
#' the salary ': 1000,
#' Welfare ': 100
#}
# name = Employee [' name ']
# print(name)
#
# sex = employee.get('sex')
# print(sex)
#
# Dept = employee.get ( 'dept' , ' other sectors')
# Print (Dept)

# member operator in determining whether the presence of key
# Print ( 'name' in Employee) True #
# Print ( 'Dept' in Employee) False #
# Print ( 'the dept' not in the Employee) True #

# traversing the dictionary
# Wang Feng
# M
# 1997-10-20
# for Key in the Employee:
# v = the Employee [Key]
# Print (v)

# name Wang Feng
# sex M
# HireDate 1997-10-20
# for K, V in employee.items ():
# Print (K, V)


# single update
# Employee [ 'Grade'] = 'B'
# Print (Employee)
# # plurality update
# employee.update (the salary = 1200, Welfare = 150)
# Print (Employee)
#
# # Add
# employee [ 'dept '] =' R & D '
Print # (the Employee)
#
# # delete
# employee.pop ( 'the dept')
# Print (the Employee)
# # delete operation to remove the last kv
# employee.popitem ()
# Print (the Employee)
#
# # Empty dictionary
# employee .clear ()
# Print (Employee)


# emp1 = { 'name': 'Jacky', 'Grade': 'B', 'HireDate': '1989-10-12'}
# {EMP2 = 'name': ' Lily ',' Grade ':' A ',' HireDate ':' 1989-10-12 '}
#
# # set default setDefault ignore the presence of absence created
# emp2.setdefault (' grade ',' C ')
# print (emp2)

acquired dictionary view #
# K = emp1.keys ()
# # dict_keys ([ 'name', 'Grade'])
# Print (K)
#
# V = emp1.values()
# # dict_values(['jacky', 'B'])
# print(v)
#
Items emp1.items = # ()
# # dict_items ([( 'name', 'Jacky'), ( 'Grade', 'B')])
# Print (items)

# format string
# emp_str = "Name: {name}, rating: {grade}, entry time {HireDate}. "format_map (emp1)
# Print (emp_str)

# hash
# h1 of = the hash (" DABC ")
# # Print (h1 of)
# # H2 = the hash ( "1231231")
# # Print (H2)

# examples
source = "12345, jace, ercd , php, 5000 $ 2345, clead, ercd, dfd, 5000 $ 22345, clead, ercd, dfd, 5000 $ 32345, clead, ercd, dfd , 5000 "
employee_list source.split = (" $ ")
Print (employee_list)

all_emp} = {
for I in Range (0, len (employee_list)):
# Print (I)
E = employee_list [I] .split (", ")
# Print (E)
employee = {'no':e[0],'name':e[1],'www':e[2],'jod':e[3],'salary':e[4]}
print(employee)
all_emp[employee['no']] = employee
print(all_emp)

empno = input('编号:')
if empno in all_emp:
emp = all_emp.get(empno)
print(emp);
else:
print('编号不存在')

Guess you like

Origin www.cnblogs.com/ericblog1992/p/11271922.html