Python打卡第二周

第一天

  1. 编码
  2. 解码
  3. os模块

 

encode和decode后面必须加上编码格式——utf-8

msg = "北京"

print(msg)

print(msg.encode(encoding="utf-8"))

print(msg.encode(encoding="utf-8").decode(encoding="utf-8"))

 

调用os函数,查看当前目录。

mkdir 创建新的文件夹

import os

cmd_res = os.system("dir")#执行命令,不保存结果

cmd_res = os.popen("dir").read()

print("-->",cmd_res)

os.mkdir("new_dir")

 

小结:调用函数,易于理解。

第二天

string的全部功能

name="my\tname is {name}  and  age is {year}"

print(name.capitalize())#首字母变大写
print(name.count("a"))#计数a出现多少次
print(name.center(50,"-"))#居中,不够50个字符用-补
#print(name.endswich("is"))
print(name.expandtabs(tabsize=10))#tab的长度
print(name[name.find("name"):])#从name开始切片
print(name.format(name='louis',year=18))#按格式输出
print(name.format_map({'name':'louis','year':18}))#按格式输出
print('ab123'.isalnum())#判断是否为字母或数字
print('aA'.isalpha())#判断是否为字母
print('1'.isdecimal())#判断是否为十进制数
print('1A'.isdigit())#判断是否为数字
print('1A'.isidentifier())#判断是不是合法的标识符
print('a'.islower())#判断是否为小写字母
print('3'.isnumeric())#判断是不是数字
print(' '.isspace())#判断是否为空格
print('My Name Is'.istitle())#判断是否为标题
print('my name is '.isprintable())#判断是否为可打印字符
print("MMMM".isupper())#判断是否为大写字母
print('+'.join(['1','2','3']))#在元素之间加格式符
print(name.ljust(50,'*'))#在右侧加*
print(name.rjust(50,'*'))#在左侧加*
print('ABC'.lower())#转换成小写字母
print('abC'.upper())#转换成大写字母
print('\nlouis'.lstrip())#去左边空格回车
print('louis   \n'.rstrip())#去掉右边回车
print('\nlouis\n'.strip())#去掉全部回车
print('------')
p = str.maketrans("luodef",'123456')

print("louis".translate(p))#根据上面的字母映射进行相应的转换

print('loulis'.replace('l','L',2))#将字符i用L代替几个
print('louis'.rfind('i'))#从左往右
print('louis lil'.split('l'))#把l当分隔符,没了
print('1\n2\n3\n4'.splitlines())#分成数组
print('louis LI'.swapcase())#全变成大写
print('louis li'.title())#变成标题
print('louis'.zfill(10))#不够用0填充

 

小结:记住常用函数,以后遇到不会的返回来查看。

第三天

  1. 切片的使用
  2. 列表的使用
  3. 列表的修改
import copy
#names = "Fengye1 Fengye2 Fengye3 Fengye4"
names = ["Fengye1","Fengye1","Fengye2",["Louis","Jack"],"Fengye3","Fengye4"]

print(names[1:-1:2])
print(names[:])
print(names[::2])
'''
name2=copy.deepcopy(names)
print(names)
print(name2)
names[1]="枫叶"
names[3][0]="LOUIS"
print(names)
print(name2)
'''
'''
names.append("Fengye5")
names.insert(0,"Fengye")
names.insert(2,"Test")
names[2]="Fengye"
print(names)

print(names[0:3])
#names.remove("fengye")
#names.pop(1)
#del names[1]
#print(names)
print(names.index("Fengye4"))
print(names.count("Fengye"))
print(names[names.index("Fengye4")])

#names.clear()
names.reverse()
#names.sort()
print(names)
name2 = {1,2,3,4}
names.extend(name2)
del name2
print(names)
print(name2)
'''
for i in names:
    print(i)

'''names.append("Fengye5")
names.insert(1,"fengye")
names.insert(3,"Ye")
names[3]="Test"
'''
'''print(names)
print(names[0])
print(names[1:3])#切片
print(names[-1])
print(names[-3:-1])
print(names[-2:])
'''

'''
names.remove("Fengye1")
del names[1]#删第几个位置
names.pop()#默认删掉最后一个

print(names.index("Fengye3"))
print(names[names.index("Fengye3")])
print(names.count("Fengye1"))
#names.clear()#清除
names.reverse()#反转
names.sort()#整理
print(names)
name2=[1,2,3,4]
names.extend(name2)#将name2添加到names
del name2#删除name2
print(names,name2)
'''

小结:了解到列表的修改,切片的使用

 

第四天

一个简易的工资购买商品程序

product_list =[
    ('iPhone',5800),
    ('Mac Pro', 9800),
    ('Bike', 800),
    ('Watch', 1600),
    ('coffee', 30),
]
shopping_list=[]
salary = input("Input your salary:")
if salary.isdigit():
    salary=int(salary)
    while True:
        for index,item in enumerate(product_list):
            print(index,item)
        choice_list = input("Input the id:")
        if choice_list.isdigit():
            choice_list=int(choice_list)
            if choice_list<len(product_list) and choice_list>=0:
                item=product_list[choice_list]
                if item[1]<=salary:
                    shopping_list.append(item)
                    salary -= item[1]
                    print("you are bought it,the balance is %s"%salary)
                else:
                    print("You money is not engouht")
        elif choice_list=='q':
            for i in shopping_list:
                print(i)
                exit()

小结:主要的函数运用 isdigit 判断是否为数字,append添加到购物车列表

 

第五天

  1. 字典的使用
  2. 字典的嵌套
av_catalog = {
    "欧美":{
        "www.youporn.com": ["很多免费的,世界最大的","质量一般"],
        "www.pornhub.com": ["很多免费的,也很大","质量比yourporn高点"],
        "letmedothistoyou.com": ["多是自拍,高质量图片很多","资源不多,更新慢"],
        "x-art.com":["质量很高,真的很高","全部收费,屌比请绕过"]
    },
    "日韩":{
        "tokyo-hot":["质量怎样不清楚,个人已经不喜欢日韩范了","听说是收费的"]
    },
    "大陆":{
        "1024":["全部免费,真好,好人一生平安","服务器在国外,慢"]
    }
}

av_catalog["大陆"]["1024"][1]="测试"

av_catalog.setdefault(("taiwan"),{"www.baidu.com":[1,2]})
print(av_catalog)





'''
'''
info={
    'stu1101':"Tenglan Wu",
    'stu1102':"Longze Luola",
    'stu1103':"XiaoZe Maliya"
}'''

'''
#info['stu1104']
print(info.get('stu1104'))#查找
print('stu1103' in info)


print(info)
print(info["stu1101"])
info["stu1101"]="武藤兰"
info["stu1104"]="Cangjingkong"

#del info["stu1101"]
#info.pop("stu1101")
#info.popitem()#随机删
'''
#print(info)
'''
b={
    'stu1101':"louis",
    1:3,
    2:5
}
info.update(b)
print(info)
c = dict.fromkeys([6,7,8],[1,{"name":"louis"},444])#初始化新字典
c[7][1]['name']="Jack"
print(c)
print(info.items())
'''
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)

小结:字典结构了解之后,需要增强实际操作运用

 

第六天

  1. 字典的嵌套
  2. 设计一个多级目录
data={
    '北京':{
        "昌平":{
            "沙河":["oldboy","test"],
            "天通苑":["链家","我爱我家"]
        },
        "朝阳":{
            "望京":{"奔驰","陌陌"},
            "国贸":{"CICC","HP"},
            "东直门":{"Advent","飞信"}
        },
        "海淀":{}
    },
    '山东':{
        "德州":{},
        "青岛":{}
    },
    '湖北':{
        "武汉":{
            "硚口":["古田"]
        }
    }

}

exit_flag=False

while not exit_flag:
    for i in data:
        print(i)

    choice = input("选择进入:")
    if choice in data:
        while not exit_flag:
            for i2 in data[choice]:
                print("\t",i2)
            choice2 = input("选择进入:")
            if choice2 in data[choice]:
                while not exit_flag:
                    for i3 in data[choice][choice2]:
                        print("\t\t",i3)
                    choice3 = input("选择进入")
                    if choice3 in data[choice][choice2]:
                        for i4 in data[choice][choice2][choice3]:
                            print(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

小结:复制的程序

 

总结:这一周计划被打乱了,因为课程变多,难以一次性吸收完,没有及时复习导致大部分忘记了。下周振作起来!

 

转载于:https://www.cnblogs.com/yuanjun93/p/10660211.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值