内容正文:
《Python字符串》单元测验
年级: 班级: 姓名: 成绩:
一、单项选择题(每题2分,共计20分)
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
1.语句'python'[2]的运行结果是( )
A. 'y' B. 't' C. 'h' D. 'o'
2.语句'c'>'a'>'B'的输出结果是( )
A.True B. False C. 'B' D. 'a'
3. 语句len('a
\\m')的输出结果是( )
A.4 B. 5 C. 6 D. 7
4. 以下关于Python字符串的描述中错误的是( )
A. 空字符串可以表示为""或''
B. 在Python字符串中,可以混合使用正整数和负整数进行索引和切片
C. 字符串'my\\text.dat'中第一个\表示转义符
D. Python字符串采用[N:M]格式进行切片,获取字符串从索引N到M的子字符串(包含N和M)
5. 字符串s="red blue",若要将其中的空格去掉,应使用函数( )
A. s.lstrip() B. s.rstrip() C. s.strip() D.s.replace(" ","")
6.Python 语言中,以下表达式输出结果为21的选项是:( )
A. print('2+1') B. print(2+1) C. print(eval('2+1')) D. print(eval('2' + '1'))
7.下列哪个字符串函数或运算符的运算结果类型不是布尔型( )
A. isdigit() B. endswith() C. find() D. in
8.已知 s = "student", 能够显示输出 student的选项是:( )
A. print(s[0:-1]) B. print(s[-1:0]) C. print(s[:6]) D. print(s[:])
9.表达式 type(eval('0j')) 的结果是:( )
A. <class ‘float’> B. <class ‘str’> C. <class ‘complex’> D. <class ‘int’>
10.已知x,y="ab",则x的值是( )
A.'a' B.'b' C.'ab' D.None
二、填空题(每空2分,共计44分)
1.已知 x = 'python',则表达式 x[4:] + x[:4] 的值为
2.语句"12"+"3"*2 的运行结果为
3.语句"computer"[1::2]的运行结果为
4.表达式'panda'[2::-1]的值为
5.语句"ewe".split('e')的运行结果为
6.语句print("#".join("123"))的运行结果为
7.表达式chr(ord(‘B’)+2) 的值为
8.语句print('12'>'3')的值为
9.表达式'%d+%c' % (66, 97)的值为
10.表达式'{:*^7.3}'.format('study')的值为
11.语句"p2p".isalpha( )的值为
12.表达式'syudy'.strip('sy')的值为
13.表达式 'Yan pei'.upper()的值为
14.表达式'panda'.capitalize()的值为
15.表达式'panda国宝'.isupper()的值为
16.表达式'yanpei'.center(10,'*')的值为
17.表达式 'ef' in 'abcdefg'的值为
18.语句'c:\test\python.py'.endswith('.py')的结果为
19.表达式'Panda'.swapcase ().swap