phthon
colan_liang
这个作者很懒,什么都没留下…
展开
-
Python运算符
Python逻辑运算符Python语言支持逻辑运算符,以下假设变量 a 为 10, b为 20:运算符 逻辑表达式 描述 实例 and x and y 布尔"与" - 如果 x 为 False,x and y 返回 False,否则它返回 y 的计算值。 (a and b) 返回 20。 or x or y 布尔"或" - 如果 x ...原创 2019-01-03 22:48:11 · 95 阅读 · 0 评论 -
Python常用语句
1、Python 条件语句用法:if 判断条件1: 执行语句1……elif 判断条件2: 执行语句2……elif 判断条件3: 执行语句3……else: 执行语句4……实例:(要注意空格对齐)num = 5 if num == 3: # 判断num的值 print 'boss' elif num == 2: pri...原创 2019-01-03 23:22:58 · 341 阅读 · 0 评论 -
Python常用函数
1、Number(数字)import randomrandom.choice(range(10))random.choice(range(10)),从0到9中随机挑选一个整数。shuffle(lst) 将序列的所有元素随机排序 uniform(x, y) 随机生成下一个实数,它在[x,y]范围内。#生成的是小数2、 字符串格式化:print "My name ...原创 2019-01-03 23:44:41 · 94 阅读 · 0 评论 -
python基础语法
1、python:查看版本或计算2、pass是保留字不能作为变量名,变量先定义后使用3、 python 对格式要求非常严格,代码块不用{}来控制,用缩进来写模块。4、多行语句用 \ 连接,total = item_one + \ item_two + \ item_three ps:语句中包含 [], {} 或 () 括号就不需要使用多行连接...原创 2019-01-02 21:32:07 · 319 阅读 · 0 评论 -
Python环境安装
1、安装Pythonhttps://www.python.org/downloads/release/python-372/Windows x86-64 executable installer2、Idea安装Python插件 3、Idea中新建文件夹,在python1.iml中编写即可。...原创 2019-01-01 16:35:52 · 152 阅读 · 0 评论 -
Python的文件IO
input函数str = input("请输入:")print "你输入的内容是: ", str结果:请输入:[x*5 for x in range(2,10,2)]你输入的内容是: [10, 20, 30, 40] close()方法write()方法# 打开一个文件fo = open("foo.txt", "w")fo.write( "www.run...原创 2019-01-06 16:45:40 · 277 阅读 · 0 评论 -
Python异常处理
异常处理try: fh = open("testfile", "w") fh.write("这是一个测试文件,用于测试异常!!")except IOError: print "Error: 没有找到文件或读取文件失败"else: print "内容写入文件成功" fh.close() 异常的参数# 定义函数def temp_conve...原创 2019-01-06 16:49:04 · 105 阅读 · 0 评论 -
Python 面向对象
创建实例对象和访问属性class Employee: '所有员工的基类' empCount = 0 def __init__(self, name, salary): self.name = name self.salary = salary Employee.empCount += 1 def displayCount(self): ...原创 2019-01-06 22:09:21 · 98 阅读 · 0 评论 -
Python变量类型
Python有五个标准的数据类型:Numbers(数字) String(字符串) List(列表) Tuple(元组) Dictionary(字典) 1、数字类型Python支持四种不同的数字类型:int(有符号整型) long(长整型[也可以代表八进制和十六进制]) float(浮点型) complex(复数)2、字符串str = 'Hello World!...原创 2019-01-02 22:54:53 · 688 阅读 · 0 评论