# reverse 反转 # list1.reverse() # print(list1) # list1.sort() # print(list1) # sort 默认升序 # 降序使用 # list1.sort(reverse=True) # print(list1) # 字典 # 1 按照key取存值 dict1={'name':'jjj','age':'18','sex':'fale'} # print(dict1['name']) # print(dict1.get('sex')) # # 使用get不会出错 # print(dict.get('sex',female)) # 会输出默认值 因为key不存在 # 成员运算 in和not in # print('name' in dict1) # 删除 del # del dict1["name"] # print(dict1) # pop ()出栈 # 不过多解释 # 随机取出字典中的popitem() # keys 和values items # print(dict1.keys()) # print(dict1.values()) # print(dict1.items()) # 循环 # for key in dict1: # print(key) # update() # 更新 操作对象为另一个字典 # dict2={"work":"student"} # dict1.update(dict2) # tuple1=(1,2,3,4,5) # 切片 # print(tuple1[0"6]) # 步长 # print(tuple1[0:6:2]) # 长度 直接LEN # 成员运算 in和 not in # 循环 # 不在赘述 # 集合类型 # 在大括号内 # 默认去重 数学性质 # set1={1,2,3,4,5,6,7,7} # 文件基本读写
# open(参数1:文件名字,参数2:操作模式,参数3:指定字符编码) # f:成为句柄 # f=open('open.txt',r) # f.write('hello tank') # res=f.read() # f.close() # 文件追加模式 a # 操作模式 # 文件处理值上下文管理:with # with会自带close()功能 # with open(r'/python/file.txt','w',encoding='utf-8') as f # f.write('list is short') # 读文件 # with open('666.jpg',,'wb') as f # f.write(res.content) # res=f.read() # print(res) # with open ('ship,mp4','rb') as f # res=f.read() # print(res) # w.write(res) # with open('tianyan_sys.mp4','rb')as f,open('tianyuan_sys_copy.mp4','wb')as w: # # 函数部分 # # def register(): # # while True: # # user=input('shuru').strip() # # pwd=input('mima').strip() # # re_pwd=input('querenmima').strip() # # if pwd==re_pwd: # # user_info=f'yonghuming:{user},mima{pwd}' # # with open(f'{user}.txt','w',encoding='utf-8') as f: # # f.write(user_info) # # break # # else: # # print("budui!") # # register() # # 只会检测python代码 其他的不会放在检测器里面 # 作业 函数登陆功能 # 让用户输入用户名与密码 # 检验用户名是否存在 # 用户名存在后检验密码 成功打印 不成功重新打印 # 输错三次退出循环 下面是作业中的登陆部分 with open('file1.text','w',encoding='utf-8') as f: f.write('用户名:jjj,密码:666666')
def login(): user = '' pwd = '' dict1 = {} with open('file1.text','rt',encoding='utf-8')as w: for line in w: line = line.split('\n')[0].split(',') for data in line: if '用户名'in data: user = data[4:] else: pwd = data[3:] dict1[user] = pwd while True: user1 = input('请输入用户名:').strip()
if user1 in dict1 : i = 1 while i <= 3: pwd1 = input('请输入密码:').strip() if pwd1 == dict1[user1]: print('登陆成功!') break else: i = i + 1 else: print('密码错误超过三次!') else: print('用户不存在!') break
login()