Python模块列表字典(2)

print(name.capitalize())    #首字母
print(name.count("a"))
print(name.center(50,"-"))
print(name.endswith("ex")) #以什么结尾
print(name.expandtabs(tabsize=30))
print(name[name.find("name"):])
print(name.format(name='alex',year=23))
print(name.format_map({'name':'alex','year':12}))
print('ab23'.isalnum())
print('abA'.isalpha())
print('1A'.isdecimal()) #十进制
print('a 1A'.isidentifier()) #判读是不是一个合法的标识符
print('a 1A'.islower())
print('33.33'.isnumeric())
print('My Name Is'.istitle())
print('My Name Is'.isprintable())
print('My Name Is'.isupper())
print(''
      '+'.join(['1','2','3']))
print(name.ljust(50,'*'))
print(name.rjust(50,'-'))
print('Alex'.lower())
print('Alex'.upper())
print('\nAlex'.lstrip())
print('\nAlex\n'.rstrip())
print('  \nAlex\n'.strip())
p = str.maketrans("abcdef",'123456')

print("alex li".translate(p))
print('alex li'.replace('l','L',1))
print('alex lil'.rfind('l'))
print('1+2+3+4'.split('+'))
print('1+2\n+3+4'.splitlines())
print('Alex Li'.swapcase())
print('lex li'.title())
print('lex li'.zfill(50))

九、字典(无序的)

字典一种key - value 的数据类型,使用就像我们上学用的字典,通过笔划、字母来查对应页的详细内容。

#!/usr/bin/env python
# -*- coding:utf-8 -*-
#key-value
'''
av_catalog = {
    "欧美":{
        "": ["很多免费的,世界最大的","质量一般"],
        "": ["很多免费的,也很大","质量比yourporn高点"],
        "letmedothistoyou.com": ["多是自拍,高质量图片很多","资源不多,更新慢"],
        "x-art.com":["质量很高,真的很高","全部收费,屌比请绕过"]
    },
    "日韩":{
        "tokyo-hot":["质量怎样不清楚,个人已经不喜欢日韩范了","听说是收费的"]
    },
    "大陆":{
        "1024":["全部免费,真好,好人一生平安","服务器在国外,慢"]
    }
}
av_catalog["大陆"]["1024"][1] = "可以在国内做镜像"

av_catalog.setdefault("taiwan",{"":[1,2]})
print(av_catalog)
'''
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)
# b = {
#    'stu1101':"Alex",
#    1:3,
#    2:5
# }
# info.update(b)
# print(info)
# c = dict.fromkeys([6,7,8],[1,{"name":"alex"},444])
# print(c)
# c[7][1]['name'] = "Jack Chen" #共用一个内存
# print(c)
# print(info.items())


# print(info)
# # print(info["stu1101"])
# print(info.get('stu1103'))
#
# print('stu1103' in info) #info.has_key("1103") in py2.x
# info["stu1101"] = "武藤兰"
# info["stu1104"] = "CangJingkong"

#del
# del info["stu1101"]
# info.pop("stu1101")
# info.popitem()
# print(info)

十、三级菜单

#!/usr/bin/env python
# -*- coding:utf-8 -*-
data = {
    '北京':{
        "昌平":{
            "沙河":["oldboy","test"],
            "天通苑":["链家地产","我爱我家"]
        },
        "朝阳":{
            "望京":["奔驰","陌陌"],
            "国贸":{"CICC","HP"},
            "东直门":{"Avent","飞信"},
        },
        "海淀":{},
    },
    '山东':{
        "德州":{},
        "青岛":{},
        "济南":{}
    },
    '广东':{
        "东莞":{},
        "常熟":{},
        "佛山":{},
    },
}
exit_flag = False

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/fd1240a6d9a745963f6151a3edf48166.html