
python
WizardtoH
做一个快乐的、优秀的码农
展开
-
python彩蛋之The Zen of Python
python中有个很有趣的“彩蛋”,也是很重要的一个“彩蛋”——The Zen of Python。输入import this之后就会出现以下的内容:The Zen of Python, by Tim PetersBeautiful is better than ugly.Explicit is better than implicit.Simple is better than com...原创 2018-11-09 21:52:17 · 491 阅读 · 0 评论 -
python函数
函数定义和调用下面的代码是简单的函数定义例子,分别是无参数函数和有参数函数:def print_hello(): print("Hello world!") def print_string(string): print(string) print_hello()print_string("test")输出:Hello world!test多个参数的函数可...原创 2019-06-13 09:19:00 · 308 阅读 · 0 评论 -
python用户输入
接收用户输入input函数能够让程序暂停运行,等待用户进行输入,并获取输入的值:#hello.pymsg = raw_input("Please input: ")print(msg)终端结果:Please input: hellohello上面的例子用的是raw_input,在python2中该函数能更好的读取字符串输入,如果使用input就需要在字符串两边加上引号。inpu...原创 2019-05-12 22:00:29 · 1691 阅读 · 0 评论 -
python语句-if、while
if语句用if语言比较是否相等/不相等:a = 1if a == 1 : print("equal")else : print("not equal")b = "test"if b != "hello" : print("not equal")else : print("equal")输出:equalnot equalif语句多个条件的与/或判断:a = 90...原创 2019-05-12 17:25:43 · 419 阅读 · 0 评论 -
python编码规范-PEP8
原文链接https://www.python.org/dev/peps/pep-0008/转载 2019-04-19 08:52:59 · 306 阅读 · 0 评论 -
python字典
使用字典python的字典由一些列key和value构成,可以用于存放同类的数据,也可以用来存放同属的数据:scores = { "xiaoming": 60, "xiaohong": 70, "xiaohei": 80}infos = { "name": "xiaoming", "age": 20, "sex": "female"}print(scores)print(infos)...原创 2019-04-27 16:54:08 · 343 阅读 · 0 评论 -
python列表操作(二)
遍历列表原创 2019-04-18 09:28:39 · 331 阅读 · 0 评论 -
python列表操作(一)
python列表原创 2019-04-13 21:46:00 · 411 阅读 · 0 评论 -
python数据类型
变量message='hello world!'print(message)输出:hello world!以上代码中,message就是一个变量,在python中使用变量时,需要遵守一些规则:变量名只能包含字母、数字和下划线。变量名可以字母或下划线打头,但不能以数字打头变量名不能包含空格,但可使用下划线来分隔其中的单词。不要将Python关键字和函数名用作变量名,例如prin...原创 2019-03-09 21:09:10 · 219 阅读 · 0 评论 -
python环境搭建
Linux和MacOsX下的python环境搭建在Linux系统和MacOsX系统中,一般都默认安装了python。可以在终端中输入python或python3进行确认,如果已经安装会显示以下内容:Python 2.7.10 (default, Jul 30 2016, 18:31:42) [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0...原创 2019-02-24 15:02:40 · 255 阅读 · 0 评论 -
python类
类的创建和使用原创 2019-06-25 22:54:53 · 278 阅读 · 0 评论