Python
韩湘
“道友你大胆地往前走!”
展开
-
Python的输入
输入语句:vin = input("Please intput:")print('Your input is '+ vin)注:python的读入均为字符串,如果需要转为int形式,则添加int (variable):num = input("Please intput your number:")num = int(num)if(num > 0): print("bi...原创 2018-10-25 11:45:09 · 310 阅读 · 0 评论 -
Python读取txt文件
readline函数;readlines函数;和open函数;原创 2019-07-22 08:03:29 · 440 阅读 · 0 评论 -
Python的矩阵操作
矩阵的生成、计算和与其他类型的转换原创 2019-07-25 16:19:42 · 3508 阅读 · 0 评论 -
Python读取文件行数
直接调用readlines函数接口:#encoding=utf-8#文件比较小count=len(open(r"train.data",'rU').readlines())print(count)借助循环计算文件行数:#文件比较大count=-1for count, line in enumerate(open(r"train.data",'rU')): count+=...原创 2019-07-16 16:18:52 · 7034 阅读 · 0 评论 -
Python中的pass语句
pass语句的作用:什么都不做;保证格式或语义完整;#hello.pyif __name__=="__main__": if(true): print("main function.") else: pass #do nothing使用环境多为执行语句部分思路还没有完成,即使用pass语句来占位;参考自博客:https://blog.csdn.ne...原创 2019-06-24 11:10:59 · 1764 阅读 · 0 评论 -
Python中int和string之间的转化
string转化为int10进制string转化为int;int('4')16进制string转化为int;int('12', 16)int转化为stringint转化为10进制string;str(18)int转化为16进制string;hex(18)参考自杜鲁门的博客:https://blog.csdn.net/bug_moving/article/...原创 2019-06-27 09:12:13 · 4358 阅读 · 0 评论 -
Python的main函数
代码样例#hello.py# Set function foo;def foo(): str="function" print(str);# This is main function;if __name__=="__main__": print("main function.") foo()其中if __name__=="__main__":表示的...原创 2019-06-22 10:12:32 · 8646 阅读 · 0 评论 -
Python numpy Import Error Something is wrong with the numpy installation. an older
Python3的numpy更新可能会出现问题报错信息:1. ImportError: Something is wrong with the numpy installation.2. UserWarning: loaded more than 1 DLL from .libs;3. ImportError: DLL load failed:原创 2019-03-28 22:50:59 · 28126 阅读 · 15 评论 -
Python读取txt的三种方法
方法一:#read txt method onef = open("./image/abc.txt")line = f.readline()while line: print line line = f.readline()f.close() 方法二:#read txt method twof = open("./image/abc.txt")for line2 in open...转载 2018-11-01 13:49:33 · 1726 阅读 · 0 评论 -
python中//和/的区别
通常C/C++中,"/ " 算术运算符的计算结果是根据参与运算的两边的数据决定的,比如:6 / 3 = 2 ; 6,3都是整数,那么结果也就是整数2;6.0 / 3.0 = 2.0 ; 6.0,3.0是浮点数,那么结果也是浮点数2.0,跟精确的说,只要" / " 两边有一个数是浮点数,那么结果就是浮点数。在Python2.2版本以前也是这么规定的,但是,Python的设计者认为这么做不符合P...转载 2018-11-01 13:46:10 · 332 阅读 · 0 评论 -
Python实现K-Means聚类
python实现代码实现效果原创 2019-07-22 08:14:41 · 274 阅读 · 0 评论