摘要: 一、进一个文件db.log ,里面放入用户名和密码,例如:admin$123456 二、面向过程程序 user = input('请输入用户名:') pwd = input('请输入用户密码:') f = open ('db','r',encoding='utf-8') for lline in f 阅读全文
posted @ 2018-06-27 23:04 黄瓜不是好瓜 阅读(183) 评论(0) 推荐(0) 编辑
摘要: 一、打开文件 二、操作文件 三、关闭文件 open(文件名,模式(只读、只写、能读能写等),编码) 四、基本的打开方式 默认是只读模式:r 只写模式:w(不可读,如果文件不存在则创建,存在则清空内容写进新内容) 只写模式:x(不可读,不存在则创建,存在则报错) 追加模式:a(不可读,不存在则创建,存 阅读全文
posted @ 2018-06-27 18:04 黄瓜不是好瓜 阅读(214) 评论(0) 推荐(0) 编辑
摘要: 65~90 为对应的大写字母 import random temp ='' for i in range(6): num = random.randrange(0,4) if num==3 or num ==1: rad2= random.randrange(0,10) temp = temp + 阅读全文
posted @ 2018-06-26 22:53 黄瓜不是好瓜 阅读(141) 评论(0) 推荐(0) 编辑
摘要: abs() 取绝对值 i = abs(123) print(i) ##输出123 all() 循环参数,如果每个元素都为真,返回真,, 假的类型:0,None, “” ,[] ,(),空值 all([True,True]) print(all) any() 只要有一个是真则为真 ascii() 对象 阅读全文
posted @ 2018-06-26 22:21 黄瓜不是好瓜 阅读(81) 评论(0) 推荐(0) 编辑
摘要: 一、加法 def func(a,b): result = a+b return resolt ret = func(1,2) print(ret) ###输出3 二、判断传入的字符串是不是标题 def funcl (a) if a.istitle(): return True else: retur 阅读全文
posted @ 2018-06-25 23:32 黄瓜不是好瓜 阅读(120) 评论(0) 推荐(0) 编辑
摘要: 一、 def f1(*a): ##形参前加一个*号,实参可以给任意多个值都可以接收 print(a) f1(123,344) 二、 def f1(**a): ##形参必须传入字典形式 print(a) f1(k1=123,k2=344) 三、 def f1(*a,**aa): ##以上两种格式的实参 阅读全文
posted @ 2018-06-25 22:12 黄瓜不是好瓜 阅读(133) 评论(0) 推荐(0) 编辑
摘要: def test(r,t,p) 形参 ret = test(p='等等',r='ere',t='csss') 实参,相等后位置上不用一一对应 默认值 def drive(name): temp = name +"开车" return temp ret = drive("一个人") print(ret 阅读全文
posted @ 2018-06-25 20:07 黄瓜不是好瓜 阅读(130) 评论(0) 推荐(0) 编辑
摘要: def test(p): ##括号里接受参数 ,形式参数 print(p) return True ret = test('给参数p赋予的值‘) ##实际参数 if ret: print('成功') else: print('失败’) expect ###try中的代码出现错误,自动执行exexce 阅读全文
posted @ 2018-06-25 19:42 黄瓜不是好瓜 阅读(132) 评论(0) 推荐(0) 编辑
摘要: def 创建函数的关键字 def test (): ##创建一个名字叫test的函数 print('Tom') ##此时并没有输出,因为函数内部代码不执行,当你调用函数的时候才执行 text()##此时调用函数,执行函数 返回值 def email(): print('我要发邮件') return 阅读全文
posted @ 2018-06-25 19:19 黄瓜不是好瓜 阅读(358) 评论(0) 推荐(0) 编辑
摘要: import copy n =123 n1 =123 n2 =copy.copy(n1) 查看id 此时id(n1)=id(n2) deepcopy 深拷贝 只要是拷贝,字符串和数字的id都是一样的 阅读全文
posted @ 2018-06-24 23:53 黄瓜不是好瓜 阅读(165) 评论(0) 推荐(0) 编辑