for循环和range()函数

>>> who = 'knights'
>>> what = 'Ni'
>>> print('We are the',who,'who say',what,what,what)
We are the knights who say Ni Ni Ni

>>> print('We are the %s who say %s'%(who,(what+' ')*4))
We are the knights who say Ni Ni Ni Ni

 

>>> foo='abc'
>>> for i in range(len(foo)):
    print(foo[i],'(%d)'%i)

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

你可能感兴趣的:(python)