Python 02
import copy
person=['name',['saving',100]]
p1=copy.copy(person)
p2=person[:]
p3=list(person)
print(p1)
print(p2)
print(p3)
p1=person[:]
p2=person[:]
p1[0]='alex'
p2[0]='fengjie'
p1[1][1]=50
print(p1)
print(p2)
# -*- coding:utf-8 -*-
data = {
'北京':{
'昌平':{
"沙河":["oldby","test"],
"tiantongyuan":["lianjie","woaiwojia"]
},
"chaoyang":{
"wangjin":["benchi","momo"],
"guomao":["CICC","HP"],
"dongzhimen":["Advent","feixin"],
},
"haidian":[],
},
'sandong':{
"得周":{},
"qingdao":{},
"jinan":{}
},
'guangdong':{
"dongguan":{},
"chagnsu":{},
"foshan":{},
},
}
exit_flag = False
while not exit_flag:
for i in data:
print(i)
choice = input("进入1》》")
if choice in data:
while not exit_flag:
for i2 in data[choice]:
print("\t",i2)
choice2 = input("进入2》》")
if choice2 in data[choice]:
while not exit_flag:
for i3 in data[choice][choice2]:
print("\t\t",i3)
choice3 = input("进入3》》:")
if choice3 in data[choice][choice2]:
for i4 in data[choice][choice2][chocie3]:
print("\t\t\t",i4)
choice = input("最后一层,按b返回》》》:")
if choice4 =="b":
pass
elif choice4 == "q":
exit_flag = True
if choice3 == "b":
break
elif choice3 == "q":
exit_flag = True
if choice2 == "b":
break
elif choice2 == "q":
exit_flag = True
# -*- coding:utf-8 -*-
av_catalog = {
"欧美":{
"www.youporn.com": ["很多免费的,世界最大的","质量一般"],
"www.pornhub.com": ["很多免费的,也很大","质量比yourporn高点"],
"letmedothistoyou.com": ["多是自拍,高质量图片很多","资源不多,更新慢"],
"x-art.com":["质量很高,真的很高","全部收费,屌比请绕过"]
},
"日韩":{
"tokyo-hot":["质量怎样不清楚,个人已经不喜欢日韩范了","听说是收费的"]
},
"大陆":{
"1024":["全部免费,真好,好人一生平安","服务器在国外,慢"]
}
}
av_catalog["大陆"]["1024"][1] = "可以在国内做镜像"
print(av_catalog)
print(av_catalog["大陆"])
print(av_catalog["大陆"]["1024"])
info = {
'stu1101': "TengLan Wu",
'stu1102': "LongZe Luola",
'stu1103': "XiaoZe Maliya",
}
b ={
'stu1101': "Alex",
1:3,
2:5,
}
info.update(b)#把b添加到info中
print(info )
c = dict.fromkeys([6,7,8],[1,{"name":"alex"},444])
print(c )
c[7][1]['name'] = "Jack Chen"
print(c)
info = {
'stu1101': "TengLan Wu",
'stu1102': "LongZe Luola",
'stu1103': "XiaoZe Maliya",
}
for i in info:
print(i,info[i])
for k,v in info.items():
print(k,v)
# -*- coding:utf-8 -*-
import copy
names = ["4ZhangYang", "#!Guyun","xXiangPeng",["alex","jack"],"ChenRonghua","XuLiangchen"]
print(names[0:-1:2])
print(names[::2])
print(names[:])
for i in names:
print(i)
name2 = copy.deepcopy(names)#浅拷贝,和原内容的地址不同
print(names)
print(name2)
names.append("LeiHaidong")#添加在列表尾部
print(names)
names.insert(1,"Chenrong")#指定位置,插入
print(names)
print(names[1:3])#切片
names.remove("Chenrong")#删除
print(names)
del names[1]#删除
print(names)
names.pop(1)#删除
print(names)
print(names.index("4ZhangYang"))#下标号
print(names.count("ChenRonghua"))#计数
names.reverse()#逆序
print(names)
names.clear()
print(names)
names2 = [1,2,3,4]
names.extend(names2)#扩展
print(names2)
# -*- coding:utf-8 -*-
name = "my \tname is {name} and i am {year} old"
print(name)
print(name.capitalize())#首字母大写
print(name.count("a"))#计数
print(name.center(50,"-"))#字符串放置为中间位置,两边用-填充
print(name.endswith("ex"))#判断字符串是否以指定后缀结尾,如果以指定后缀结尾返回True,否则返回False
print(name.expandtabs(tabsize=30))#把字符串中的 tab 符号('\t')转为空格,tab 符号('\t')默认的空格数是 8。
print(name[name.find("name"):])#是否包含子字符串,如果包含子字符串返回开始的索引值,否则返回-1。
print(name.format(name='alex',year = 23))
print(name.format_map({'name':'alex','year':10}))
print('ab23'.isalnum)#Python isalnum() 方法检测字符串是否由字母和数字组成。
print('abA'.isalpha())#Python isalpha() 方法检测字符串是否只由字母或文字组成。
print('1A'.isdecimal())#isdecimal() 方法检查字符串是否只包含十进制字符。这种方法只存在于unicode对象。
print('1A'.isdigit())
print("1》-----------------------")
print('a 1A'.isidentifier())#方法用于判断字符串是否是有效的 Python 标识符,可用来判断变量名是否合法。
print('33A'.isnumeric())#检测字符串是否只由数字组成,数字可以是: Unicode 数字,全角数字(双字节),罗马数字,汉字数字。
print('My Name Is '.istitle())#测字符串中所有的单词拼写首字母是否为大写,且其他字母为小写。
print('My Name Is '.isprintable()) #如果所有字符都是可打印的,则 isprintable() 方法返回 True,否则返回 False。
print('My Name Is '.isupper())#检测字符串中所有的字母是否都为大写。
print("2》》---------------------")
print('+'.join( ['1','2','3']) )#将序列中的元素以指定的字符连接生成一个新的字符串。
print( name.ljust(50,'*') )#返回一个原字符串左对齐,并使用空格填充至指定长度的新字符串。如果指定的长度小于原字符串的长度则返回原字符串。
print( name.rjust(50,'-') )#右对齐
print( 'Alex'.lower() )#所有小写
print( 'Alex'.upper() )#所有大写
print( '\nAlex'.lstrip() )#lstrip() 方法用于截掉字符串左边的空格或指定字符。
print( 'Alex\n'.rstrip() )
print( ' Alex\n'.strip() )#用于移除字符串头尾指定的字符(默认为空格)或字符序列。
p = str.maketrans("abcdefli",'123$@456')#
print("alex li".translate(p) )
print("-----------------------------")
print('alex li'.replace('l','L',1))
print('alex lil'.rfind('l'))
print('1+2+3+4'.split('\n'))
print('1+2\n+3+4'.splitlines())
print('Alex Li'.swapcase())#小写变大写,大写变小写
print('lex li'.title())#每个单词的首字母大写
print('lex li'.zfill(50))#右侧用0填充,指定长度
# -*- coding:utf-8 -*-
product_list = [
('Iphone',5800),
('Mac Pro',9800),
('Bike',800),
('Watch',10600),
('Coffee',31),
('Alex Python',120),
('Exit','q'),
]
shopping_list = []
salary = input("Input your salary:")
if salary.isdigit():
salary = int(salary)
while True:
for index,item in enumerate(product_list):
#print(product_list.index(item),item)
print(index,item)
user_choice = input("选择要买嘛?:::》》")
if user_choice.isdigit():
user_choice = int(user_choice)
if user_choice < len(product_list) and user_choice >=0:
p_item = product_list[user_choice]
if p_item[1] <= salary: #买的起
shopping_list.append(p_item)
salary -= p_item[1]
print("Added %s into shopping cart,your current balance is \033[31;1m%s\033[0m" %(p_item,salary) )
else:
print("\033[41;1m你的余额只剩[%s]啦,还买个毛线\033[0m" % salary)
else:
print("product code [%s] is not exist!"% user_choice)
elif user_choice == 'q':
print("--------shopping list------")
for p in shopping_list:
print(p)
print("Your current balance:",salary)
exit()
else:
print("invalid option")