循环打印字符串
b = 'abc'
for s in b:
print( s )
range循环打印1~100
for i in range(1,101):
print( i )
根据下标循环取值,打印26个英文字符,用range函数和len函数
s = 'abcdefghijklmnopqrstuvwxyz'
for i in range (len(s) ):
print( s[ i ] )
截取字符串
s = 'abcdefghijklmnopqrstuvwxyz'
print(s [1:6] )
倒着截取一个字符串
s = 'abcdefghijklmnopqrstuvwxyz'
print (s [-1])#倒着截取一个
print(s [1:6])#截取五个数
print(s [0:10:4])#步数
倒着截取指定字符串
利用range函数倒着写出
s = 'ABCDEFGHIJk'
print(len(s))
for i in range (-1,-12,-1):
print(s[i])
s = 'ABCDEFGHIJk'
for i in range(10,0,-1):
print(s[i])