Python小技巧

格式化输出

'Hi, %s, you have $%d.' % ('Michael', 1000000)

'Hello, {0}, 成绩提升了 {1:.1f}%'.format('小明', 17.125) #传入的参数依次替换字符串内的占位符{0}、{1}

把list变成带索引的可迭代对象

from collection import Iterable
isinstance([5,6,7],Iterable)
for indexL,valueL in enumerate([7,8,9]):
    print(indexL,valueL)

 Python packages: https://pypi.org/

如果要获得一个对象的所有属性和方法,可以使用dir()函数

posted @ 2019-07-11 09:35  WindyZ  阅读(96)  评论(0编辑  收藏  举报