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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM