Python 字符串切片练习:s[-4:], s[:-4] 的输出结果
题目: 138.s = 'the sky is blue',表达式 print(s[-4:], s[:-4]) 的结果是( ) A) sky is blue the B) blue is sky the C) the sky is blue D) blue the sky is
答案: A) sky is blue the
解析: s[-4:] 表示从倒数第四个字符开始到字符串末尾,即 'blue' 和 'the';s[:-4] 表示从字符串开头到倒数第四个字符,即 'sky is '。因此,print(s[-4:], s[:-4]) 的结果为 'blue the' 和 'sky is ',按照顺序输出即可得到答案 A) sky is blue the。
原文地址: https://www.cveoy.top/t/topic/f2CP 著作权归作者所有。请勿转载和采集!