![](https://img-blog.csdnimg.cn/20190927151053287.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
Python
Python
summeryan2011
这个作者很懒,什么都没留下…
展开
-
异常 except
目录try...except...常见的异常try...except...elsetry...except...finallyraisetry...except...>>> open("abc.txt", 'r')Traceback (most recent call last): File "<pyshell#133>", line 1, in <module> open("abc.txt", 'r')FileNot...原创 2021-12-07 10:59:55 · 173 阅读 · 0 评论 -
module 模块
>>> from time import sleep>>> sleep(2)>>> import time>>> time.sleep(1)>>> from time import *>>> sleep(2)>>> import time>>>help(time)同目录调用test_sample- test_21072201....原创 2021-12-06 19:31:56 · 513 阅读 · 0 评论 -
class 类
class MyClass(): def say_hello(self, name): return "hello, {}".format(name) def add(self, a: int, b: int): return a + bmc = MyClass()print(mc.say_hello("haha"))print(mc.add(10, 31))class A: def __init__(self, a, b):...原创 2021-12-06 17:43:33 · 58 阅读 · 0 评论 -
Python3 字典
>>> dicts = {"username": "zhangsan", "password": "123456", "address": "guangdong"}>>> dicts.keys()dict_keys(['username', 'password', 'address'])>>> dicts.values()dict_values(['zhangsan', '123456', 'guangdong'])新增>&原创 2021-12-06 14:24:40 · 1124 阅读 · 0 评论 -
print() 格式化输出
>>> name = 'tom'>>> age = 23>>> print("name is: " + name + "age is: " + str(age))name is: tomage is: 23>>> print("name is: %s, age is: %d" %(name, age))name is: tom, age is: 23推荐使用下面这种:>>> print(("nam原创 2021-12-06 11:55:02 · 222 阅读 · 0 评论 -
Python之禅
>>> import thisThe Zen of Python, by Tim PetersBeautiful is better than ugly. 优美胜于丑陋Explicit is better than implicit. 明了胜于晦涩Simple is better than complex. 简单胜过复杂Complex is better than complicated. 复杂胜过凌乱Flat is better than nested. 扁平胜于...原创 2021-12-06 11:41:24 · 536 阅读 · 0 评论 -
Python操作Excel文档
需要安装xlrd(pip install xlrd),并导入(import xlrd) xlrd-2.0.1目前只支持.xls文件,.xlsx会报错 xlrd.open_workbook(r"文件路径") # 打开文件,文件路径带\,需要在前面加r转义 sheet = wb.sheet_by_name("Sheet1") # 进入Sheet1,区分大小写 sheet.nrows # 获取Sheet1的行数 sheet.row_values(0) # 获取第一行的内容,返回的是一个list...原创 2021-11-21 20:44:40 · 833 阅读 · 0 评论 -
ModuleNotFoundError: No module named ‘pip‘
在Python的安装目录Scripts下,可以看到有pip.exe,运行pip命令提示ModuleNotFoundError: No module named 'pip'在windows窗口下执行这个命令:python -m ensurepip我是执行了这个命令就可以了的,如果还不行,更新pip再试下:python -m pip install --upgrade pip...原创 2021-11-20 15:13:58 · 1978 阅读 · 0 评论 -
Jupyter Notebook
安装Python3.8以上版本pip3 install jupyter notebook -- 待验证启动jupyter notebook原创 2021-11-16 17:04:47 · 588 阅读 · 0 评论 -
记一个超有用的网址 - python
https://github.com/amoyshmily/learning/blob/master/SuperNotes/Python/crazyIT.md原创 2019-10-23 15:43:43 · 109 阅读 · 0 评论 -
推导(comprehension)
推导基础:[<i表达式> for i in aiterator]aiterator指一个可遍历对象,比如列表、元组、也可以是range()用循环变量i去遍历aiterator,并将i相关表达式的值放入一个列表中。例:square = [i*i for i in range(1, 11)] =>[1, 4, 9, 16, 25, 36, 49, 64, 81,...原创 2019-10-06 11:32:16 · 146 阅读 · 0 评论 -
数据类型-字符串(str)
通过序号来读取其中某个字符:'abc'[1] = 'b'可以通过运算符运算:'aaa' + 'bbb' = 'aaabbb'; 'a'*3 = 'aaa'; 效率没有join()高原创 2019-09-30 11:17:51 · 187 阅读 · 0 评论 -
数据类型-数字(Number)
Python 支持三种不同的数值类型:整型(Int)- 通常被称为是整型或整数,是正或负整数,不带小数点。Python3 整型是没有限制大小的,可以当作 Long 类型使用,所以 Python3 没有 Python2 的 Long 类型。 浮点型(float)- 浮点型由整数部分与小数部分组成,浮点型也可以使用科学计数法表示(2.5e2 = 2.5 x 102= 250) 复数( (...原创 2019-09-30 11:16:30 · 204 阅读 · 0 评论 -
os.system路径存中有空格
其实没有搞清楚原理是什么,只是把所有答案都试了一遍,发现下面这个是管用的,留个记号os.system(r'"文件路径"')r单引号双引号,引号顺序反了还不行了原创 2017-05-02 11:36:46 · 5802 阅读 · 0 评论 -
python计算利息
# coding:utf-8s = 0# 每月存的本金base = 5000# 期望利率rate = 1.05year = 5month = year*12for i in range(0, month): s = s + base * pow(rate, i/12)print "本金+利息:", sprint "本金:", 5000*monthprint "利息:...原创 2018-07-09 16:34:07 · 19310 阅读 · 0 评论 -
一个自动化例子
1. 点击跳转到另一个页面,或需要等待加载值,需要增加等待时长 import time time.sleep(3) 2. 含中文字符比较失败,windows和python默认编辑不一样,强制转换成python的默认编码utf-8 reload(sys) sys.setdefaultencoding('utf8')3. 按模块名称来查找元素 find_...原创 2018-08-13 10:57:27 · 2342 阅读 · 0 评论 -
Python3 列表
list1 = ['Google', 'Runoob', 1997, 2000];list2 = [1, 2, 3, 4, 5, 6, 7 ];list1[0] ='Google'; # 第一个索引是0;最后一个索引是-1list2[1:5] =[2, 3, 4, 5]; #切片更新列表:list1[2] = 2001;删除列表:del list1[2];Python列表函数 len(list):列表元素个数 max(list):返回列表元素最大值 m...原创 2019-03-05 15:28:27 · 115 阅读 · 0 评论 -
Python3 元组
Python 的元组与列表类似,不同之处在于元组的元素不能修改。tup1 = ('Google', 'Runoob', 1997, 2000);tup2 = (1, 2, 3, 4, 5, 6, 7 )创建空元组 tup1 = ();元组中只包含一个元素时,需要在元素后面添加逗号,否则括号会被当作运算符使用:tup1 = (50,)tup1[0]: Googletup2...转载 2019-03-05 15:48:56 · 108 阅读 · 0 评论 -
python - if
ifif condition_1: statement_block_1elif condition_2: statement_block_2else: statement_block_3if 表达式1: 语句 if 表达式2: 语句 elif 表达式3: 语句 else: 语句...转载 2019-03-14 16:53:53 · 72 阅读 · 0 评论 -
python - 循环
while 循环while 判断条件: 语句while 循环使用 else 语句count = 0while count < 5: print (count, " 小于 5") count = count + 1else: print (count, " 大于或等于 5")简单语句组类似if语句的语法,如果你的while循环体中只有一条...转载 2019-03-14 17:13:22 · 355 阅读 · 0 评论 -
print() 参数
print的完整格式为print(objects,sep,end,file,flush),其中后面4个为可选参数sep:在输出字符串之间插入指定字符串,默认是空格>>> print('a','b','c')a b c>>> print('a','b','c', sep = '/')a/b/cend:在print输出语句的结尾加上指定字符串,默...原创 2019-09-18 11:44:49 · 2050 阅读 · 0 评论 -
sys.stdout.write()
print(obj)实质就是调用sys.stdout.write(obj+’\n’)sys.stdout是python中标准输出流# 两者等价sys.stdout.write('hello'+'\n')print('hello')print()重定向到某个指定文件:给sys.stdout赋值,修改它的指向import syssys.stdout = open('test...原创 2019-09-18 14:46:18 · 4658 阅读 · 0 评论 -
python运算优先级
从高到低依次为算术运算符:**优先级最高 位运算符 比较(关系)运算符 is 运算符:is、is not in 运算符:in、not in 逻辑运算符:not >and >or...原创 2019-09-23 14:30:36 · 464 阅读 · 0 评论 -
python ImportError: DLL load failed: %1 不是有效的 Win32 应用程
连接数据库时报错1. ORA-24315: 非法的属性类型2.python ImportError: DLL load failed: %1 不是有效的 Win32 应用程原因:Oracle客户端与cx_Oracle版本不一致查询Oracle客户端版本:sqlplus -v--SQL*Plus: Release10.2.0.1.0 - Productioncx_原创 2017-03-15 13:51:03 · 1832 阅读 · 0 评论