![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Python常见笔试编程题
小白头一号
这个作者很懒,什么都没留下…
展开
-
切片-dump、load;深拷贝、浅拷贝
""" # 切片 l = ['xiaoming', 'xiaohei', 'xiaobai', 'xiaohong','xiaolv'] print(l[0:2]) # 顾头不顾尾,指针0和1的值,结果:['xiaoming', 'xiaohei'] print(l[:2]) # 前面的不写默认从0开始,结果:['xiaoming', 'xiaohei'] print(l[2:]) ...原创 2020-02-19 23:22:21 · 138 阅读 · 0 评论 -
json操作
字典与json 互转 # json 就是一个字符串 d = { "username": "xiaoming", "password":"123456啊" } import json with open('userjson.txt', 'w', encoding='utf-8') as f: # 把字典转成json字符串, # ensure_ascii=False:...原创 2020-02-15 19:36:11 · 94 阅读 · 0 评论 -
登录程序
# 登录程序: # 1、账号、密码不能为空 # 2、要校验账号是否存在 # 3、最多输入3次。 # 4、账号不区分大小写 # 5、账号、密码长度要大于等于6且小于等于12 # 6、每次登录的时候密码错误,就在账号后面加一个失败次数 # 思路 # 1、读取文件,读取用户名和密码、次数,保存到字典里 # 2、最多错误三次 # 3、输入账号、密码 # 4、校验不为空 # 5、校验长度[6-12] # 6...原创 2020-02-13 20:53:23 · 559 阅读 · 0 评论 -
注册流程
# 写注册程序,账号密码存到文件里,最多输入3次 # input('username') # input('passwd') # input('cpasswd') # 文件格式 # 小明,123456 # 1、需要校验账号是否存在, # 2、2次输入密码是否一致, # 3、不能为空 # 4、账号不区分大小写 # 5、账号密码长度要大于等于6且小于等于12 # # 思路 # 1、输入账号、密码、确认...原创 2020-02-13 20:23:24 · 240 阅读 · 0 评论 -
字符串常用操作
s = ' ab c ' s = s.strip() #移除字符串头尾的空格或者回车符 print(s) # 打印结果: # ab c #判断字符串是否为空 str="hello" if str.strip()=="": print("str is null") if str.strip(): print("str is not null") split() str.spl...原创 2020-02-13 20:16:16 · 96 阅读 · 0 评论 -
读写文件
修改文件 读写r、r+、w、w+、a、a+ r只读,r+读写,不创建 w新建只写,w+新建读写 a附加写;a+附加读写 a+ 读的前需要f.sesk(0),否则读出来的是空内容 f = open(r'exampleFile.txt', 'a+', encoding='utf-8') result = f.read() print("文件内容:", result) f.seek(0) result2...原创 2020-02-05 23:31:17 · 70 阅读 · 0 评论 -
判断是否是负小数
def check_float(string): s = str(string) if s.count('.') == 1: # 判断小数点个数 sl = s.split('.') # 按照小数点进行分割 left = sl[0] # 小数点前面的 right = sl[1] # 小数点后面的 if left....原创 2019-12-24 18:15:27 · 179 阅读 · 0 评论 -
冒泡排序-从小到大
def bubbleSort(arr): n = len(arr) # 遍历所有数组元素 for i in range(n): # Last i elements are already in place for j in range(0, n - i - 1): if arr[j] > arr[j + 1...原创 2019-12-24 17:42:47 · 273 阅读 · 0 评论 -
Python常见笔试编程题-#监控服务器日志,找出每分钟访问超过100次的ip地址
import time point = 0 while True: f = open(r'access.log') f.seek(point) ips = {} for line in f: if line.strip(): ip = line.split()[0] if ip not in ips: ips[ip] = 1 else: ips[i...原创 2019-11-27 19:40:47 · 426 阅读 · 0 评论 -
Python常见笔试编程题
Python常见笔试题 关于字符串 #有如下字符串,要求编码输出其中的:shuidi l = ‘welcome to shui&di’ import re l = 'welcome to shui&di' newl= re.search('welcome to (.*?)&(.*)', l) print(newl.group(1)+ newl.group(2)) ...原创 2019-11-26 19:33:07 · 676 阅读 · 0 评论