5th Day of Python Learning

Source: Internet
Author: User

Dictionary additions and Deletions change

Dic1 ={"name": "Chun Sheng", "age": +, "sex": "Male"}
# dic1["Asdas"]= "DFDSF" add default Last
# Print (DIC1)
# dic1["Age"]=20//If a built-in value is overridden
# Print (DIC1)
#
# Dic1.setdefault ("weight")//with built-in values do not make any changes without adding a build value to
#dic1. SetDefault ("Weight", 150)//Add build value pair
#print (DIC1)
# Dic1.setdefault ("5", "5")
# Print (DIC1)



#删

# Print (Dic1.pop ("name"))///The return value is deleted as built
#print (Dic1.pop ("SSS", "None")) #//can set the return value
#print (DIC1)


#print (Dic1.popitem ()) #随机删除 There is a value in the returned value tuple that is deleted

# del dic1["name"]
# Print (DIC1)

# del dic1//delete list will be an error
# Print (DIC1)


# dic1.clear ()//Empty list
# Print (DIC1)

#改


# dic1["Name"]=1 #//Press Build to change
# Print (DIC1)

# dic={"name": "Jinag", "Age": "$", "sex": "Male"}
# dic2={"name": "Alex", "Weight": 75}
# dic.update (DIC2) #/////update changed
# Print (DIC)
# Print (DIC2)

#结果:
# {' name ': ' Jinag ', ' age ': ' + ', ' sex ': ' Male '}
# {' name ': ' Jinag ', ' weight ': *, ' age ': ' ' ', ' sex ': ' Male '}

#查
#print (Dic1.keys ()) #//
#print (Dic1.values ())//value
#print (Dic1.items ())//is a list inside is Ganso dict_items ([' Name ', ' Spring '), (' Age ', '), (' Sex ', ' male ')])
#
# for I in Dic1:
# print (i)//Cha Jian
# for I in Dic1.keys ():
# Print (i)

# for I in Dic1.values ()://Check value
# Print (i)


#面试题
# a,b=1,2
# a=1
# b=2
# A,b=b,a
# print (A, B)

Dictionary nesting

Build it up to find

In the go to delete and change to search

5th Day of Python Learning

Related Article

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.