zoukankan      html  css  js  c++  java
  • Python字符串跨行的方式

    通过三引号编写多行字符串时,会包含构造引号中的换行符、空格或制表符:

    >>> if True:
    ...     s = """
    ...     你好!
    ...     我是萌萌!
    ...     """
    ...     print(s)
    ... 
    
            你好!
            我是萌萌!
    
    >>> len(s)
    14
    >>> s
    '
    	你好!
    	我是萌萌!
    	'

    如果只是想要把单行字符串写在多行上,并且不想要多余的符号,可以这样做:

    >>> if True:
    ...     s = (
    ...     "你好!"
    ...     "我是萌萌!"
    ...     )
    ...     print(s)
    ... 
    你好!我是萌萌!
    >>> len(s)
    8
    >>> s
    '你好!我是萌萌!'

    或者是这样做(建议使用上面的方式):

    >>> if True:
    ...     s = 
    ...     "你好!"
    ...     "我是萌萌!"
    ...     print(s)
    ... 
    你好!我是萌萌!
    >>> len(s)
    8
    >>> s
    '你好!我是萌萌!'
  • 相关阅读:
    Subsets
    Search a 2D Matrix II
    Search a 2D Matrix
    Search Insert Position
    Search for a Range
    Sort Colors
    Sort List
    语音笔记04-3 TEHO,COR
    语音笔记04-2 拨号规则
    语音笔记04-1 CME实验
  • 原文地址:https://www.cnblogs.com/hanxiaomeng/p/12737468.html
Copyright © 2011-2022 走看看