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)

最新文章

  1. mylistview 中item的子项的布局文件xml
  2. 【matlab】libsvm-3.18安装与使用
  3. spring,hibernate,struts的面试笔试题
  4. Sublime Text 3使用技巧
  5. javascript图片切换
  6. sampler2d
  7. Catalyst揭秘 Day2 Catalyst源码初探
  8. php中的修饰符
  9. linux 清空文件内容命令
  10. 【CF】304 E. Soldier and Traveling
  11. Windows平台下,Scrapy Installation,安装问题解决
  12. MySQL主从问题
  13. C#获取mac
  14. Aix字符集
  15. 为VS2013添加SQLCE的支持
  16. -ms-grid -ms-grid-rows -ms-grid-row -ms-grid-columns -ms-grid-column
  17. [其他]volatile 关键字
  18. 两种方法实现asp.net方案的前后端数据交互(aspx文件、html+ashx+ajax)
  19. php redis 操作
  20. mybatis mapper.xml的特殊操作符

热门文章

  1. 前后端分离进行权限管理之后端API返回菜单及权限信息(三)
  2. 【记坑】Oracle数据库Date类型查询结果多出".0"的解决方法
  3. vue 初始化rem
  4. layer.msg的使用
  5. 【TCP】SYN攻击
  6. javascript表单验证的例子
  7. renren-fast-vue-动态路由
  8. hive UDAF开发和运行全过程
  9. TI低功耗蓝牙(BLE)介绍【转】
  10. 巧用Wget快速建立文件下载中心