46 python学习笔记
2024-09-01 12:05:20
0 引言
之前用python跑过深度学习的代码,用过一段时间的jupiter和tensorflow;最近在Ubuntu下搭建起了VSCode + Anaconda的python开发环境,感觉很好用,尤其是用来做算法验证简直舒服得一匹。遂单独开一贴,记录一下python学习与使用中的一些好玩的点。
1 python中的函数参数
python是弱参数类型语言,这符合当前高级变成语言发展的趋势。我是从c++新标准中提倡使用的auto开始了解这一趋势的,后来在《面向对象编程》一课中,写jsp的时候,用到了var,也是根据初始化参数类型推测变量的类型。如今,python将这一趋势发扬光大,使得语言变得及其好用,简直舒服极了!!!
在python的函数定义中,延续了这一特点,使得其函数的定义方式天然就就具有重载性质,显示出了无与伦比的优美与简洁,举例如下。
from shapely.geometry import Point
from shapely.geometry import LineString
from shapely.geometry import Polygon
from shapely.geometry import MultiPoint # 不指定参数类型,实际上相当于无限重载
def outputAllAttributes(mem):
print('geom_type',mem.geom_type)
print('area',mem.area)
print('bounds',mem.bounds)
print('length',mem.length)
print('distance',mem.distance)
print('representative_point',mem.representative_point)
print('\n') def test():
# Point/LineString/Polygon类型的形参通过同一个函数调用,完美体现面向对象中“重载”的思想
p = Point(0,0)
outputAllAttributes(p)
line = LineString([(0,0), (0,1), (1,1),(1,0)])
outputAllAttributes(line)
poly = Polygon([(0,0), (1,1), (1,2)])
outputAllAttributes(poly) if __name__ == '__main__':
test()
2 Python函数是传值还是传引用
看了一贴,链接如下。
https://www.cnblogs.com/loleina/p/5276918.html
结论:python不允许程序员选择采用传值还是传引用。Python参数传递采用的肯定是“传对象引用”的方式。这种方式相当于传值和传引用的一种综合。
如果函数收到的是一个可变对象(Number,String, Tuple)的引用,就能修改对象的原始值--相当于通过“传引用”来传递对象。
如果函数收到的是一个不可变对象(List,Dictionary,Set)的引用,就不能直接修改原始对象--相当于通过“传值'来传递对象。
3 python打包与生成.exe文件
https://blog.csdn.net/orangefly0214/article/details/81462245
# 介绍了setuptools的用法
https://www.cnblogs.com/mywolrd/p/4756005.html
# 介绍了将朋友python程序打包成linux/windows可执行文件的操作方法
4 bug修复
(1)python matplotlib中文显示有问题。
https://jingyan.baidu.com/article/908080223cd201fd91c80fd5.html
(2)How to get the mpl_toolkits to install
https://github.com/matplotlib/matplotlib/issues/4546/
conda install pyqt #神奇地解决了
5 python编程惯例
https://github.com/jackfrued/Python-100-Days/blob/master/Python%E7%BC%96%E7%A8%8B%E6%83%AF%E4%BE%8B.md
(1)if __name__ == '__main__':
代码既可以导入,又可以执行
(2)in: 包含和迭代
if x in items: # 包含
for x in items: # 迭代
(3)zip组合键和值来创建字典
keys = ['', '', '']
values = ['骆昊', '王大锤', '白元芳']
d = dict(zip(keys, values))
print(d)
最新文章
- mylistview 中item的子项的布局文件xml
- 【matlab】libsvm-3.18安装与使用
- spring,hibernate,struts的面试笔试题
- Sublime Text 3使用技巧
- javascript图片切换
- sampler2d
- Catalyst揭秘 Day2 Catalyst源码初探
- php中的修饰符
- linux 清空文件内容命令
- 【CF】304 E. Soldier and Traveling
- Windows平台下,Scrapy Installation,安装问题解决
- MySQL主从问题
- C#获取mac
- Aix字符集
- 为VS2013添加SQLCE的支持
- -ms-grid -ms-grid-rows -ms-grid-row -ms-grid-columns -ms-grid-column
- [其他]volatile 关键字
- 两种方法实现asp.net方案的前后端数据交互(aspx文件、html+ashx+ajax)
- php redis 操作
- mybatis mapper.xml的特殊操作符