Python百题计划

时间:2020-12-23 06:07:44

一、基础篇

  1. 想要像类似执行shell脚本一样执行Python脚本,需要在py文件开头加上什么?KEY:#!/usr/bin/env python
  2. Python解释器在加载 .py 文件中的代码时,会对内容进行编码(默认ascill),我们应该选择什么编码?如何配置? KEY:UTF8 | # -*- coding: utf-8 -*-
  3. Python中使用什么符号做注释,多行注释使用什么? KEY:# | 三个连续的单引号或三个连续的双引号
  4. Python中的单引号和双引号有无区别? KEY:无
  5. Python中使用什么命令导入模块? KEY:import modulename
  6. py文件在执行过程中会自动生成一个与其同名的 .pyc 文件,它是什么?有什么用?KEY:pyc是由py文件经过编译后二进制文件,py文件变成pyc文件后,加载的速度有所提高,而且pyc是一种跨平台的字节码,是由python的虚拟机来执行的.
  7. 按Python中的变量定义,以下哪个是合法变量? [A: _name1 B:123 C:class D:abc-] KEY:A
  8. Python使用缩进作为语法边界,一般建议怎样缩进?
    A.TAB    B.两个空格      C.四个空格      D.八个空格
    KEY:C

  9. print(100 - 25 * 3 % 4) 打印的结果是?
    A.1    B.97    C.25    D.82

    KEY:B

  10. 下列语句中,非法的是_____?
    A.x=y=1
    B.x=(y=1)
    C.x,y=y,x
    D.x=1;y=1
    KEY:B

  11. >>> n = 3
    >>> a = 1 if n > 2 else 3
    >>> a
    输出结果是_______?
    KEY:1

  12. >>> a = lambda x: x+1
    >>> a(1)
    输出结果是_______?
    KEY:2

  13. >>> chr(65)
    输出结果是_______?
    KEY:'A'

  14. >>> ord("A")
    输出结果是_______?
    KEY:65

  15. >>> n = 8
    >>> n.bit_length()
    结果是_______?
    KEY:4

  16. >>> hash(1.0) == hash(1) 输出结果是? KEY:True
  17. >>> a = 0x11
    >>> b = 0o11
    >>> c = 0b11
    a + b + c 的值为_____?
    KEY:29

  18. >>> print('Alex'.center(6, '*'))
    结果是_______?
    KEY:'*Alex*'

  19. >>> list1 = ["Alex", "is", "handsome"]
    >>> "_".join(list1)
    输出结果是_______?
    KEY:'Alex_is_handsome'

  20. >>> 'www.oldboyedu.com'.replace('w', '*', 1)
    结果是_______?
    KEY:'*ww.oldboyedu.com'

  21. >>> 'www.oldboyedu.com'.split('.', 1)
    结果是_______?
    KEY:['www', 'oldboyedu.com']

  22. >>> 'www.oldboyedu.com'.partition('.')
    结果是_______?
    KEY:('www', '.', 'oldboyedu.com')

  23. >>> 'www.oldboyedu.com'.strip('zaw.')
    结果是_______?
    KEY:'oldboyedu.com'

  24. >>> list1 = [4,1,5,3,2]
    >>> list2 = list1.sort()
    >>> list2
    结果是_______?
    KEY:None

  25. >>> list1 = [4,1,5,3,2]
    >>> list2 = sorted(list1)
    >>> list2
    输出结果是_______?
    KEY:[1, 2, 3, 4, 5]

  26. >>> list2 = sorted(list1, reverse=True)
    >>> list2
    输出结果是_______?
    KEY:[5, 4, 3, 2, 1]

  27. >>> list1 = [1, 3, 5, 2, 4]
    >>> list1 = list1[::-1]
    >>> list1
    结果是?
    KEY:[4, 2, 5, 3, 1]

  28. >>>list1=[[]]*2
    >>>list1
    [[], []]
    >>>id(list1[0])==id(list1[1])
    结果是?
    KEY:True(列表复制其实复制的是引用)

  29. >>>list1=[[] for i in range(2)]
    >>>list1
    [[], []]
    >>>id(list1[0])==id(list1[1])
    结果是?
    KEY:False(重新生成了列表)

  30. >>> list1 = [1, 2, 3, 6, 7]
    >>> min(list1, key=lambda x: x%2)
    结果是_______?
    KEY:2

  31. >>> list1 = [1, 2, 3, 6, 7]
    >>> max(list1, key=lambda x: x%2)
    结果是_______?
    KEY:1

  32. >>> list1 = [1, 3, 3, 5, 7]
    >>> set(list1)
    结果是?
    KEY:{1, 3, 5, 7}

  33. >>> divmod(99, 2)
    结果是?
    KEY:(49,1)

  34. >>>num="四"
    >>>num.isdigit()
    False
    >>>num._______()
    True
    _______ 上应填?
    KEY:isnumeric

  35. >>> result = 1 if 'a'>'b' else 2
    >>> result
    结果是?
    KEY:2

  36. >>> dict1 = {"a": 1, "b": 2}
    >>> result = dict1.get("c")
    >>> print(result)
    结果是?
    KEY:None

  37. >>> list1 = [1, 3, 2, 6, 5]
    >>> list1.sort(_______)
    >>> list1
    [6, 5, 3, 2, 1]
    _______ 上应填?
    KEY:reverse=True

  38. >>> list1=[1, 2, 3]
    >>> list2=list1.reverse()
    >>> print(list2)

    打印的结果为_______?
    KEY:None

  39. >>> list1=[1, 2, 3]
    >>> list2=list1_______
    >>> list2
    [3, 2, 1]

    _______ 上应填写什么内容?

    KEY:[::-1]

  40. 下面选项中,不能创建字典的语句是( )
    A.dict1 = {}
    B.dict2 = {1: 2}
    C.dict3 = {[1]: 2}
    D.dict4 = {(1): 2}
    KEY:C

  41. >>> dict1 = {'a': 1,'b': 2}
    >>> dict1.setdefault('c', 3)
    >>> dict1['c']
    结果为______?
    KEY:3

  42. >>> dict1 = {"a": 1, "b": 2}
    >>> list(dict1)

    上述代码的输出结果是_______?
    KEY:["a", "b"]

  43. >>> nums={1, 2, 2, 3, 4, 4, 5}
    >>> len(nums)
    结果是_____?
    KEY:5

  44. for i in range(2):
        print(i)
    for j in range(4, 6):
        print(j)

    上述代码执行的结果是____?

    A:12456    B:01456    C:0145    D:2456
    KEY:C

  45. >>> list1 = [1, 3, 5, 7]
    >>> for i in list1:
    ... if i > 6:
    ... break
    ... else:
    ... print(i, end="")
    ... else:
    ... print("over", end="")
    上述代码输出的结果是_______?
    KEY:135

  46. >>> import copy
    >>> a = [1, 2, 3, ["a", "b", "c"]]
    >>> b = a
    >>> c = copy.copy(a)
    >>> d = copy.deepcopy(a)
    >>> (id(a) == id(b), id(a) == id(c), id(a) == id(d), id(a[0]) == id(c[0]), id(a[0]) == id(d[0]), id(a[3]) == id(c[3]), id(a[3]) == id(d[3]))
    结果为________?

    A:(True, True, False, True, True, True, True)
    B:(True, False, False, True, True, True, False)
    C:(True, False, False, False, False, False, False)
    D:(True, True, False, True, True, True, False)
    KEY:B

  47. >>> list1 = [1, 3, 5, 7, 9]
    >>> a = _____(1, 3)
    >>> list1[1:3]
    [3, 5]
    >>> list1[a]
    [3, 5]
    _______ 上应填?
    KEY:slice

  48. >>> a = {1, 2, 3}
    >>> b = {3, 4, 5}
    >>> a&b

    结果是_______?
    KEY:{3}

  49. >>> a = {1, 2, 3}
    >>> b = {3, 4, 5}
    >>> a|b

    结果是_______?
    KEY:{1, 2, 3, 4, 5}

  50. >>> a = {1, 2, 3}
    >>> b = {2, 3, 4}
    >>> a.update(b)
    >>> a
    结果是_______?
    KEY:{1, 2, 3, 4}

  51. python my.py a1 a2 形式运行脚本时,通过 from sys import argv 如何获得参数a2的值?
    A.argv[0]     B.argv[1]     C.argv[2]     D.argv[3]
    KEY:C

  52. 以下哪个函数的参数定义非法?
    A.def myfunc(*args):
    B.def myfunc(arg1=1):
    C.def myfunc(*args, a=1):
    D.def myfunc(a=1, **args):

    KEY:D

  53. num = 10
    def func():
        num = 5
    func()
    print(num)
    输出的结果是_____?
    KEY:10

  54. num = 10
    def fun():
        num = 5
    print(fun())
    输出的结果是_____?
    KEY:None

  55. def func1():
    for i in range(1, 5):
    return i

    def func2():
    for i in range(1, 5):
    yield i

    表达式 func1()+sum(func2()) 的值为____?
    KEY:11

  56. 表达式 issubclass(bool, int) 的值为____?
    KEY:True

  57. 表达式 True + False 的值为____?
    KEY:1

  58. >>> f=open('test.txt','r')
    >>> print(f.read())
    name:Alex

    >>> f.seek(5)
    >>> print(f.read())
    打印的结果是_____?

    KEY:Alex

  59. >>> list1 = [1, 3, 5]
    >>> list2 = list(map(lambda x: x + 1, list1))
    >>> print(list2)

    打印的结果是_______?
    KEY:[2, 4, 6]

  60. >>> list1 = [11, 33, 55]
    >>> list2 = list(filter(lambda x: x > 22, list1))
    >>> print(list2)

    打印的结果是_______?
    KEY:[33, 55]

  61. >>> from functools import reduce
    >>> reduce(lambda x,y : x if x < y else y, [44,11,22,7,31])
    上述代码的输出结果为______?

    KEY:7

  62. >>> from functools import reduce
    >>> reduce(lambda x, y:x+y, [1, 2, 3, 4, 5],1)
    结果是_______?
    KEY:16

  63. >>> file_path = "D:\Alex\demo.py"
    >>> os.path.dirname(file_path)
    输出结果是_______?
    KEY:'D:\Alex'

  64. >>> import re
    >>> ret=re.match('\d', 'a1b2c3')
    >>> print(ret)
    结果是_______?
    A:None B:1 C:123 D:[]
    KEY:A

  65. >>> list1 = list(range(1, 10, 2))
    >>> list1
    结果是_______?
    KEY:[1, 3, 5, 7, 9]