小编Pet*_*bot的帖子

一个方法比另一个更接近Pythonic?

显然地

方法1

if var in ['string one', 'string two']:
    do_something()
Run Code Online (Sandbox Code Playgroud)

更像Pythonic比:

方法2

if var == 'stringone' or var == 'stringtwo':
    dosomething()
Run Code Online (Sandbox Code Playgroud)

为什么方法1被认为比方法2更像Pythonic?

python

4
推荐指数
2
解决办法
108
查看次数

标签 统计

python ×1