摘要: def test1(x,y=2): print(x,y) test1(1) test1(1,3) test1(1,y=4) #默认参数特点:调用函数的时候,默认参数非必须传递,默认参数放在后边 #用途:默认(安装)值 def test2(*args):#可变长参数(参数组),args被视为一个元组。 print(args) test2(1,4,5,9) a=test2(*[2,... 阅读全文
posted @ 2018-01-24 19:28 耐烦不急 阅读(216) 评论(0) 推荐(0) 编辑
摘要: def test1(): '只执行return以前的' print('test1返回值为0 ') return 0 print('这句不会被执行的') x=test1() print(x)#值为0 def test2(): '无返回值' print('test2无返回值') print(test2())#无返回值,打印的是None def te... 阅读全文
posted @ 2018-01-24 16:30 耐烦不急 阅读(473) 评论(0) 推荐(0) 编辑
摘要: def test1(x,y): print(x,y) test1(1,2)#位置参数调用,按顺序来,与形参一一对应 test1(y=1,x=2)#输出为2 1,不是1 2。关键字参数调用按关键字,不按位置,与形参位置无关 #test1(y=1,2)错误,无法执行 test1(2,y=1)#位置参数调用,关键字参数调用,按照位置参数调用,但是不能给同一个参数赋多个值 注:关键字参数调用要放... 阅读全文
posted @ 2018-01-24 16:30 耐烦不急 阅读(213) 评论(0) 推荐(0) 编辑
摘要: """写两个函数,分别求两个整数的最大公约数和最小公倍数,调用这两个函数,并输出结果。两个整数由键盘输入。""" ''' 设两个整数u和v,用辗转相除法求最大公约数的算法如下: 例如:u=4和v=6 if v>u v>u即:4<6 将变量u与v的值互换(使大者u为被除数) ... 阅读全文
posted @ 2018-01-24 14:17 耐烦不急 阅读(7726) 评论(0) 推荐(0) 编辑
摘要: "常用Tkinter组件的使用" #一、弹出消息框 #1 弹出提示消息框 from tkinter.messagebox import * showinfo(title='提示',message='欢迎光临') #2 弹出警告消息框 from tkinter.messagebox import * showwarning(title='提示',message='请输入密码') #3 弹出错误消息... 阅读全文
posted @ 2018-01-24 11:13 耐烦不急 阅读(2036) 评论(2) 推荐(0) 编辑
摘要: import time def logger(): """追加写""" time_format='%Y-%m-%d %X'#年-月-日 小时分钟秒 time_current=time.strftime(time_format) with open('uuu.txt','a+') as f: f.write('%s end action\n'%tim... 阅读全文
posted @ 2018-01-22 13:17 耐烦不急 阅读(226) 评论(0) 推荐(0) 编辑
摘要: ''' 三种编程方式:1.面向对象 (类:class)2.面向过程 (过程:def)3.函数式编程(函数:def) 编程语言中函数的定义:函数是逻辑结构化和过程化的一种编程方法 过程与函数的区别,过程是没有返回值的,函数是有返回值的,例子如下 ''' #过程 def fun1(): """描述函数1功能""" print('in the fun1') #函数(将一段段的功能包含到... 阅读全文
posted @ 2018-01-21 21:32 耐烦不急 阅读(442) 评论(0) 推荐(0) 编辑
摘要: #python3默认是Unicode,Unicode是万国码,不管中文字符还是英文,所有的每个字符都占2个字节空间,16位 #python2默认是ascii码 #ascii码不能存中文,一个英文只能占一个字节,8位;utf-8是可变长的字符编码(可认为Unicode的扩展集),所有英文字符仍按ASCII码形式,即1个字节,所有中文字符按3个字节储存。gbk和gb2312两个字节表示一个中文。 #... 阅读全文
posted @ 2018-01-21 20:07 耐烦不急 阅读(490) 评论(0) 推荐(0) 编辑
摘要: python3默认是Unicode,不用声明# -*- coding:utf-8 -*-,如果声明则是utf-8 unicode='你好' print('utf-8:',unicode.encode())#encode成utf-8,转码之后会变成byte类型 unicode_to_gbk=unicode.encode('gbk')#默认就是unicode,不用再decode,直接可以转成gbk ... 阅读全文
posted @ 2018-01-21 20:07 耐烦不急 阅读(311) 评论(0) 推荐(0) 编辑
摘要: name='Qi Zhiguang' name2='ZhangMeng' print("Hi!"+name)#用加号,后边must be str print('Hi!',name) print("Hi!%s"%(name)) print('Hi!%s,Hi!%s'%(name,name2)) print("the length of (%s) is %d"%(name,len(name))) p... 阅读全文
posted @ 2018-01-21 17:27 耐烦不急 阅读(227) 评论(0) 推荐(0) 编辑