python基础编程

(一)Python编写,输入一个字符串,输出字符串中每个字符和它的下标组成的新字符串

方法一:

s=input('input a string:')
s1=''.join(['%s%d' % (s[i],i) for in range(len(s))])
print(s1)
 
方法二:
def printStr():
    s=raw_input("Input a string:")
    l=[]
    s2=''
    l=list(s)
    for in range(len(l)):
        s2=s2+l[i]+str(i)
    print s2
(二)Python 中如何将一个字符串以特定字符分割存入到列表中

"150526087:o7nL74Ikiy4"

将上面的字符串输出成

【‘150526087’,‘o7nL74Ikiy4’】

解析:用split

str = "150526087:o7nL74Ikiy4"
print str.split(":")

 
posted @ 2020-03-15 12:10  人生&不将就  阅读(195)  评论(0)    收藏  举报