码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2016-08-15 17:24:27      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:

#!/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

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

标签:

原文地址:http://www.cnblogs.com/feifei168/p/5773630.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!