可爱的python

本文分享了作者在CheckIO上完成的Morsclock题目心得,并介绍了从高手解决方案中学到的两个Python技巧:使用str.format()进行格式化字符串以及使用replace()方法替换字符。

每天在checkio上写一道题来锻炼锻炼思维

今天写完morse clock之后观摩best solution的时候学习了两样东东:

dev:python3.3

1.str.format()

eg. 

>>>'{0:02b} '.format(2)

10

'''

{} : replacement_field

':' indicator

in this example,

0 : fieldname

02b :form_spec, just like %02b in c

'''

2.replace()

string.replace(s, old, new[, maxreplace])

eg.

>>> '010000'.replace('0','.')
'.1....'

’replace or match’ may involve some problems about greedy match, for further discussion

for further discusion

高手写的东东确实值得消化,重要的不是解决了问题,而是为什么要解决这个问题以及如何高效地解决问题。

赞同一种观点,好的程序员都是有好想法的家伙~么么

 

转载于:https://www.cnblogs.com/rainy-mayday/p/3304506.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值