LPTHW NOTES 1

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 13,490评论 0 23
  • NAME dnsmasq - A lightweight DHCP and caching DNS server....
    ximitc阅读 7,954评论 0 0
  • 我认为最开心的班队会 骑天大胜 焦点少年班坚持分享第46天 2017.9.12星期二 曾经的班队会很枯燥无味,感...
    她说梦里花会开阅读 1,508评论 0 0
  • 01 中午,大雨来袭,狂风大作,屋里半开的窗户,风吹来,刹那间把门关上。雨穿过窗户,落到屋里。想起来,外面阳台的下...
    山寸阅读 2,839评论 0 0
  • 如果你说你在下午四点来,从三点钟开始,我就开始感觉很快乐,时间越临近,我就越来越感到快乐。 到了四点钟的时候,我就...
    a0613515b241阅读 1,040评论 0 1

友情链接更多精彩内容