带括号/逗号的多行 Python 代码的第二行的推荐标准缩进是什么?
无缩进:
plt.imshow(np.transpose(Z), extent=[0,4.2,0,48000], cmap='jet', vmin=-100, vmax=0, origin='lowest', aspect='auto')
4 个空格缩进:
plt.imshow(np.transpose(Z), extent=[0,4.2,0,48000], cmap='jet', vmin=-100, vmax=0, origin='lowest', aspect='auto')
直到
(
:plt.imshow(np.transpose(Z), extent=[0,4.2,0,48000], cmap='jet', vmin=-100, vmax=0, origin='lowest', aspect='auto')
另一种解决方案?
这是链接:Proper indentation for Python multiline strings但这里的问题特定于带括号/逗号的多行,而不是字符串。
最佳答案
我永远不会使用选项 1 或 2,它们可能会产生误导。如果你有足够的空间,3是好的。
There is one more option which can be used when option 3 leaves too little room or when splitting lines using a backslash (PyCharm defaults to this in the latter situation), two indentation levels (8 spaces):
plt.imshow(np.transpose(Z), extent=[0,4.2,0,48000], cmap='jet',
vmin=-100, vmax=0, origin='lowest', aspect='auto')
def grouper_with_prev(iterable: _Iin[_T], n: int, include_first: bool = False) \
-> _Iout[_t.Tuple[_T, ...]]:
"""
Returns n size chuncks of iterable with the previous n-1 elements
"""
...
这不会混淆选项 1 和 2,使您在做什么很明显。
关于python - 带括号的多行代码第二行的正确缩进,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51675818/