day2

Posted whz_it

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了day2相关的知识,希望对你有一定的参考价值。

三级目录

__author__ = ‘weihui‘

data = {
    ‘北京‘:{
        "昌平":{
            "沙河":["oldboy","test"],
            "天通苑":["链家地产","我爱我家"]
        },
        "朝阳":{
            "望京":["奔驰","陌陌"],
            "国贸":{"CICC","HP"},
            "东直门":{"Advent","飞信"},
        },
        "海淀":{},
    },
    ‘山东‘:{
        "德州":{},
        "青岛":{},
        "济南":{}
    },
    ‘广东‘:{
        "广州":{},
        "深圳":{},
        "佛山":{},
    },
}
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][choice3]:
                            print("\t\t",i4)
                        choice4 = 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

 

列表操作

__author__ = ‘weihui‘
# -*- coding:utf-8 -*-
import copy
names = ["张三",["李四","shui"],"王五","小明"]
passwd = ["123456","234567","345678","456789"]
#print(names)
#print(names[1:3])#切片
#print(names[-2:])
#names.append("小明")
#names.insert(1,"三毛")#插入
#print(names)
#names[2] = "这是谁"
#print(names)
#del names[2]
#names.pop()
#names.remove("王五")
#print(names)
#print(names.index("王五"))
#print(names[names.index("王五")])
#print(names.count("王五"))
#names.reverse()
#print(names)
#names.sort()
#print(names)
#del passwd
#names.extend(passwd)
#print(names,passwd)
names2 = names.copy()
print(names2)
names[1] = "xiaoer"
print(names)
name3 = copy.deepcopy(names)
print(name3)
for i in name3:
    print(i)
print(name3[::2])

#浅copy
‘‘‘
person = [‘name‘,[‘a‘,100]]
p1=copy.copy(person)
p2=person[:]
p3=list(person)
‘‘‘

#person = [‘name‘,[‘abc‘,100]]

 

字典

__author__ = ‘weihui‘

info = {
    ‘stu1‘: ‘1001‘,
    ‘stu2‘: ‘1002‘,
    ‘stu3‘: ‘1003‘,
}
print(info)
#print(info[‘stu1‘])
#info[‘stu1‘] = ‘abc‘
#print(info)
#del info["stu1"]
#print(info)
info.pop(‘stu2‘)
print(info)
print(info.get(‘13423‘))#试试utf-8
print(info.keys())
print(info.values())
b = {
    ‘edw‘:‘1313‘,
    ‘feq‘:‘4321‘,
    ‘stu2‘:‘1234‘,
}
info.update(b)
print(info)
c = dict.fromkeys([6,7,8],"test")
print(c)

 

字符串

__author__ = ‘weihui‘
# -*-coding:utf-8 -*-

name = "name is {name}, age is {age}"
print(name.capitalize())
print(name.count(‘w‘))
print(name.center(50,‘-‘))
print(name.endswith("sha?"))
print(name.expandtabs(tabsize=30))
print(name[name.find(‘name‘):])
print(‘abc123!‘.isalnum())#阿拉伯字母
print(‘acx‘.isalpha())#英文字符
print(‘12‘.isdigit())
print(‘+‘.join([‘1‘,‘2‘,‘3‘]))
print(name.ljust(50,‘*‘))
print(name.rjust(50,‘*‘))
print(‘WHZ‘.lower())
print(‘whz‘.upper())
print(‘whz\n‘.rstrip())
print(‘--‘)
print(‘\nwhz‘.lstrip())#去空格
p = str.maketrans("abcd",‘1234‘)
print("whz ls".translate(p))
print("whz ls".replace(‘w‘,‘h‘,1))
print("hwyslswl".rfind(‘l‘))
print("qfhqk qjf".split("h"))

 

以上是关于day2的主要内容,如果未能解决你的问题,请参考以下文章

Python学习-day2

DAY2-介绍准备

day2:写几段代码

Day2 - Python模块-01

python修炼之路-day2

DAY2