题解 | #截取字符串#
截取字符串
https://www.nowcoder.com/practice/a30bbc1a0aca4c27b86dd88868de4a4a
from collections import deque def read_first_k_items(n,k): str_n =list(n) queue = deque() if k >= 1 and k <= 1000: for items in range(0,k): queue.append(str_n[items]) return str(''.join(queue)) if __name__=='__main__': n,k = str(input()),int(input()) print(read_first_k_items(n,k))
将字符串n转化为list,然后遍历前n个元素