题解 | #截取字符串#

截取字符串

http://www.nowcoder.com/practice/a30bbc1a0aca4c27b86dd88868de4a4a

# -*- coding: utf-8 -*-
while True:
    try:
        str_n = raw_input()#获得字符串
        k = int(input())#获得k
        srt_out = []
        for x in range(k):
            srt_out.append(str_n[x])
        print(str(srt_out).replace("[","").replace("]","").replace(",","").replace("'", "").replace(" ", ""))#将列表转化为字符串
    except:
        break

全部评论

相关推荐

点赞 评论 收藏
转发
点赞 收藏 评论
分享
牛客网
牛客企业服务