LPTHW NOTES 1

作者: 小黑天天快乐 | 来源:发表于2016-10-31 19:29 被阅读0次

    format string 

    conversion characters:

    r     raw string

    s     string

    %   a '%' character

    f     floating point number

    e    floating point number exponential format ( lowercase )

    i     signed integer

    print 'i like %s like %s%s' % ('nothing','this'+'ever','hi')

    ## string+string is considered as one string

    round(number[,ndigits])  (四舍五入)

    Return the floating point value number rounded to ndigits digits after the decimal point. If ndigits is omitted, it defaults to zero. The result is a floating point number. Values are rounded to the closest multiple of 10 to the power minus ndigits; if two multiples are equally close, rounding is done away from 0 (so, for example, round(0.5) is 1.0 and round(-0.5)is-1.0).

    Note

    The behavior of round() for floats can be surprising: for example, round(2.675,2)gives2.67instead of the expected2.68. This is not a bug: it’s a result of the fact that most decimal fractions can’t be represented exactly as a float.  SeeFloating Point Arithmetic: Issues and Limitations for more information.

    slicing

    >>> 'abcd'[0:2]

    'ab'                ## left : close  right : open

    >>> 'hello' == 'HELLO'

    False            ## uppercase and lowercase are different

    >>> 'world'[:-1]

    'worl'             ## if not pointed out, from left to right

    相关文章

      网友评论

        本文标题:LPTHW NOTES 1

        本文链接:https://www.haomeiwen.com/subject/jkmputtx.html