ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

day3

2019-06-21 09:51:08  阅读:179  来源: 互联网

标签:dict1 list1 day3 pwd user print open


#今日内容 #1 数据类型剩余的内置方法 #2 字符编码 #3 文件处理 #4 函数基础 #列表里类型 list1=['tank','18','nan','guangdong'] #list1.insert(2,'oldboy')#插入函数 插入位置,插入内容 # 2为索引 #CTRL +斜杠呼出注释 #print(list1) #print(list1.count('tank')) #count 输出索引 #clear 清空 #list1.clear() #print(list1) # list2=list1.copy() #不同于 = #复制 直接赋值 完全复制 # list3=list1 # list1.append('666') # print(list2) # print(list3) # =对后面有影响 是地址赋值 #以上是浅拷贝 #下面是深拷贝 # from copy import deepcopy # list4=deepcopy(list1) # list1.append('asd') # print(list1) # print(list4) # 没有变化 # extend 合并 # list2=[1,2,3] # list3=[4,5,6] # list2.extend(list3) # print(list2)

 

# 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()  

标签:dict1,list1,day3,pwd,user,print,open
来源: https://www.cnblogs.com/zhendejinitaimei/p/11062784.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有