python学习笔记enumerate()与range(len)运用及赋值小计

#!/uer/bin/env python
# _*_ coding: utf-8 _*_

#格式1
a = 'abc'
for i in range(len(a)):
    print a[i],'(%d)'% i

a (0)
b (1)
c (2)

#格式2
for A,i in enumerate('abc'):
    print i,A

a 0
b 1
c 2

#格式2.1
b = raw_input('wartyouname:')
for i,j in enumerate(b):
    print b[i],'(%d)'% i

wartyouname:ssdf
s (0)
s (1)
d (2)
f (3)

  

 

#!/uer/bin/env python
# _*_ coding: utf-8 _*_

who = 'kingfei'
what = 'NI'
print 'We are the',who,'who say',what,what,what,what
print 'We are the  %s  who say   %s ' % (who,(what + ' ') *4)    #注意代码'空格'

  输出:

We are the kingfei who say NI NI NI NI
We are the kingfei who say NI NI NI NI

转载于:https://www.cnblogs.com/feifei168/p/5773630.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值