Python 咸鱼日记
6.3-7.0 7/7 I AM BACK!!!!!
How to store one user’s info?
User_0={
‘user’:’xxx’ –for the name, anything need letters- you need use ‘’, for number and other numeric value, no ‘’ needed
‘first_name’:’xxxx’
}
How to dig out all information?- not a single value – as- name but how about first and last?
Key-value: value is the value of the key
For key,value in dic.items()(user_0)- items function
Tab print(f””)-represents key
Tab print(f””)-represents value
/ print(f”xxxxxxx{key}+{value}.title()”)
This is a loop!!!!
Key and value’s name can be changed according to your set- just needs to be easy to claim!
When the value in dic. Is not needed??
Keys()-the key in set would be dragged out
For name in favorite_language.keys(_)
Print(name.title())
What if only part of info. In dic. Are needed?
1. Which key is needed??
Name={“a”,”b”}
2. Find their value?
For name in xxx.keys()
Print(hi{})
3. if name in Name
language =xxxx[xx].title(_)-the value in these two keys
print(_)
what if I want to sort the value in dic??
Use sorted(_)
Exp. For name in sorted(………):
Only interested in value in dic.
Values()
For…..in favorite_language.values():
Also-in values it could be the same in some different keys –use set() function to delete the repeat value
Aliens-alien_1,alien_2,alien_3
Alien_1{‘color’:’’,’point’:5….}
For alien in aliens:
Print(alien)
What if there are more than three alines??
Exp. We need 30 aliens-use range functions-range()
Range(30) and cutting –we need first three-[:3]
Put it into the end of the set -.append(_)
Len(aliens)-to count how many aliens in this set
Change the info??
==-this is for the check –is it in xxx?
If alien[‘color’]==’green’
Then if it is green
We need to change it into other color
Use =
Elif == ‘’
What if we have multiple values in one key
Pizza-topping – more than one topping- extra chesse,green pepper
Use [] [‘’.’’]
For topping in pizza[‘toppings’]:
Print(“\t”+topping)!!!