python 运算符



除法运算(/),整除运算(//),计算求余(%),(**) 乘方运算,变量赋值(=),字符串有多种表现形式,
用单引号('……')或双引号("……")标注的结果相同 ,反斜杠 \ 用于转义

    >>> 17 / 3  # classic division returns a float
    5.666666666666667
    >>>
    >>> 17 // 3  # floor division discards the fractional part
    5
    >>> 17 % 3  # the % operator returns the remainder of the division
    2
    >>> 5 * 3 + 2  # floored quotient * divisor + remainder
    17
    >>> 5 ** 2  # 5 squared
    25
    >>> 2 ** 7  # 2 to the power of 7
    128
    >>> width = 20
    >>> height = 5 * 9
    >>> width * height
    900
>>> 'doesn\'t'  # use \' to escape the single quote...
"doesn't"
>>> "doesn't"  # ...or use double quotes instead
"doesn't"
>>> print('"Isn\'t," they said.')
"Isn't," they said.

如果不希望前置 \ 的字符转义成特殊字符,可以使用 原始字符串,在引号前添加 r 即可:
 >>> print('C:\some\name')  # here \n means newline!
C:\some
ame
>>> print(r'C:\some\name')  # note the r before the quote
C:\some\name
posted on 2023-01-29 09:29  宇宇小子  阅读(24)  评论(0)    收藏  举报