Python百題計劃

1、基礎篇

  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:Cpython

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

    KEY:Bshell

  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:1post

  12. >>> a = lambda x: x+1
    >>> a(1)
    輸出結果是_______?
    KEY:2編碼

  13. >>> chr(65)
    輸出結果是_______?
    KEY:'A'blog

  14. >>> ord("A")
    輸出結果是_______?
    KEY:65ip

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

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

  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]

相關文章
相關標籤/搜索