Day3-python Study Notes (iii)

Source: Internet
Author: User

one. Dictionary Operations
# string, Integer, list, dictionary
# stus = [
# [' Little Fu ', ' + ', ' nan ', ' xxx ', ' 20k ']
# [' Little Fu ', ' + ', ' nan ', ' xxx ', ' 20k ']
# [' Little Fu ', ' + ', ' nan ', ' xxx ', ' 20k ']
# [' Little Fu ', ' + ', ' nan ', ' xxx ', ' 20k ']

#字典 k=v, convenient value, fast speed
D = {' name ': ' Little Fu ',
' Age ': 18,
' Sex ': ' Male ',
' Addr ': ' Fanyu District ',
' Money ': 100000
}
#字典 Check
#print (d[' name ')
#print (d[' money ')
#print (d[' haha ') if you write a nonexistent key, you will get an error.
# Print (D.get (' sdasd ')) #查询无此key, return none, nonexistent key, no error
# Print (D.get (' sdasd ', ' Can't find ') #

#字典 Increase
# d[' Height ']=178
#d. SetDefault (' weight ', 130) can only be added and cannot be modified
# #字典是无序的,
# print (d)

#字典 modification
# d[' height ']=200# if this key exists, modify his value and if key does not exist, add a

#字典 Delete
# d.pop (' sex ') #删除某个key
#d. Popitem () #随机删除一个
#del d[' age ')
#d. Clear () #清空字典
# Print (D.keys ())
# Print (D.values ())
# d.hash_key (' addr ') #python2里面字典有这个方法, do you have this key
# if ' addr ' in D:
# print (' addr ')

#for k,v in D.items (): #循环字典, turn dictionary key,value into a two-dimensional array with poor performance
#print (D.items ())

# for K in D: #性能好
# print (K,d[k])
# Print (K,d.get (k))

res = list (D.items ())
Print (Res[1])
# # int () #转换成int类型
# # str () #转换成字符串类型
# # list () #转换成list类型
# res = list (D.items ())
# print (res[2])

#数组, dictionary nesting queries, etc.

# stus=[

# {' name ': ' Bin ',
# ' age ': 18,
# ' sex ': ' Male ',
# ' addr ': ' Changping District ',
# ' money ': 100000,
# ' Jinku ': {
# ' $ ': 50000,
# ' ¥ ': 8000
#
# }
# },
# {' name ': ' Bin 1 ',
# ' age ': 18,
# ' sex ': ' Male ',
# ' addr ': ' Changping District ',
# ' money ': 100000,
# ' bag ': {
# ' Nike ': ' A car '
#
# }
# }
# ]
# Print (stus[0][' Jinku ' [' ¥ '])
# #print (stus[' TLX ' [' money '])
# Print (stus[1][' bag ' [' Nike '])

Stus = {
' YBQ ': {
' Age ': 18,
' Sex ': ' Male ',
' Addr ': ' Changping District ',
' Money ': 10000000,
' Jinku ': {
' CCB card ': 80000,
' Business card ': 800000,
' Investment card ': 8000000
}
},
' TLX ': {
' Age ': 19,
' Sex ': ' Woman ',
' Addr ': ' Changping District ',
' Money ': 10000000,
' Huazhuangpin ':
[' Cha ', ' haha ']

},
' MPP ': {
' Age ': 19,
' Sex ': ' Woman ',
' Addr ': ' Changping District ',
' Money ': 10000000,
"Bag": {
' LV ': ' A car ',
' Crocodile ': 10
}
},
}
# Print (stus[' TLX ' [' money '])
# Print (stus[' MPP ' [' Bag '].keys ())
#
# All_money = stus[' YBQ ' [' Jinku '].values ()
# # print (All_money)
# # print (sum (All_money))
# Sum_money = 0
# for money in All_money:
# Sum_money = Sum_money + Money
# Print (Sum_money)

#print (stus[' TLX ' [' Huazhuangpin '][1])



# All_money = stus[' YBQ ' [' Jinku '].values ()
# #print (sum (All_money))
# Sum_money = 0
# for money in All_money:
# Sum_money=sum_money +money
#
# Print (Sum_money)
Print (stus[' TLX ' [' Huazhuangpin '][1])

Day3-python Study Notes (iii)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.