1.2.3 循环

来源:互联网 发布:好桌道类似软件 编辑:程序博客网 时间:2024/05/21 18:20
for i in range(0,100):
        print(i)

print("item" + i)        #如果在输出时添加“item”,则会报错,字符串不匹配  

修改 字符串拼接
    print("item {0}".format(i))

Update.
    print("item {0},{1}".format(i,"hello python")

>>> print("item {0}{1}" . format(2333 , "hello python"))
item 2333hello python
>>> print("item {0},{1}" . format(2333 , "hello python"))
item 2333,hello python
>>> print("item {0} {1}" . format(2333 , "hello python"))
item 2333 hello python

cf : 三种字符串拼接是一样的
    print( "%s" % ( "strings"))
    print( "{0}" . format("strings")
    print( "{name}" . format(name = "bob")

0 0
原创粉丝点击