使用Python过程中遇到的问题

Python 问题集

1.使用try...except...语句捕获异常时应尽量指定异常的具体类型。

2.format输出百分数的形式:

format(4.2/5.1,'.2%’) -> 82.35%

3.使用list.append()会返回一个Nonetype的类型,
可以使用两个list相加的方法。

4.Python文件读写:r-只读,w-只写,a-追加

5.Python url中包含中文,编码问题。使用urlencode()函数。

from urllib.parse import urlencode
app_name = '水果忍者'
parameters = {'key': app_name} # dict
key = urlencode(parameters)
search_url = 'http://www.wandoujia.com/search?'+key  # http://www.wandoujia.com/search?key=%E8%AF%B4%E5%95%A5

6.Mac上pip install装包出现权限错误时,可以使用这种方式:pip install --user

7.Python初始化二维数组:
multilist = [[0 for col in range(5)] for row in range(3)]
参考:http://www.cnblogs.com/coderzh/archive/2008/05/18/1201993.html

8.字典按value排序:
sorted(dict1, key=dict1.get)
理解key=dict1.get: http://stackoverflow.com/questions/39496096/understanding-dictionary-get-in-python/39496240

Python学习资料

1.Python Best Practices Guidebook :https://github.com/kennethreitz/python-guide

转载于:https://www.cnblogs.com/binwone/p/6041613.html

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值