1.10 哪些情况下不需要续行符? ============================= .. image:: http://image.iswbm.com/20200804124133.png 在写代码时,为了代码的可读性,代码的排版是尤为重要的。 为了实现高可读性的代码,我们常常使用到的就是续行符 ``\``\ 。 .. code:: python >>> a = 'talk is cheap,'\ ... 'show me the code.' >>> >>> print(a) talk is cheap,show me the code. 那有哪些情况下,是不需要写续行符的呢? 经过总结,在这些符号中间的代码换行可以省略掉续行符:\ ``[]``,\ ``()``,\ ``{}`` .. code:: python >>> my_list=[1,2,3, ... 4,5,6] >>> my_tuple=(1,2,3, ... 4,5,6) >>> my_dict={"name": "MING", ... "gender": "male"} 另外还有,在多行文本注释中 ``'''`` ,续行符也是可以不写的。 .. code:: python >>> text = '''talk is cheap, ... show me code.''' >>> 但是这种写法回车会自动转化为 ``\n`` .. code:: python >>> text = '''talk is cheap, ... show me code.''' >>> text 'talk is cheap,\nshow me code.'