Various Python Exam Question Banks (Candidates' Memories Version) Check it out!

foreword

Let me share with you the python test questions that I have personally experienced

Remember to pay attention~

You can refer to the following questions to practice. The exam questions are changed without changing the medicine. I hope it will be helpful to you~

1. Multiple choice questions

1. Which of the following statements is illegal in Python? (B)

A、x = y = z = 1 B、x = (y = z + 1)

C、x, y = y, x D、x += y

2. Regarding Python memory management, which of the following statements is wrong (B)

A. Variables do not need to be declared in advance B. Variables can be used directly without creation and assignment

C. Variables do not need to specify the type D. You can use del to release resources

3. Which of the following is not a valid Python identifier (B)

A、int32 B、40XL C、self D、__name__

4. Which of the following statements is wrong (A)

A. Except for dictionary types, all standard objects can be used for Boolean testing

B. The Boolean value of an empty string is False

C. The Boolean value of an empty list object is False

D. The Boolean value of any number object with a value of 0 is False

5. The data types not supported by Python are (A)

A、char B、int C、float D、list

6. Regarding complex numbers in Python, which of the following statements is wrong (C)

A. The syntax for plural numbers is real + image j

B. Both real and imaginary parts are floating point numbers

C. The imaginary part must be suffixed with j and must be lowercase

D. The method conjugate returns the conjugate complex number of a complex number

[----Help Python learning, all the following learning materials are free at the end of the article! ----】

7. Which of the following statements about character strings is wrong (B)

A. Characters should be treated as strings of length 1

B. The string ends with \0 to mark the end of the string

C. Both single quotes and double quotes can be used to create strings

D. Special characters such as newline and carriage return can be included in the triple-quoted string

8. The following statement that cannot create a dictionary is (C)

A、dict1 = {} B、dict2 = { 3 : 5 }

C、dict3 = {[1,2,3]: “uestc”}

D、dict4 = {(1,2,3): “uestc”}

9. Which of the following Python statements is correct (D)

A、min = x if x < y else y

B、max = x > y ? x : y

C、if (x > y) print x

D、while True : pass

10. For information processing and information storage in computers (A)

A binary code

B Decimal code

C hex code

D ASCII code

11. How to execute python source program (B)

A compile and execute B analyze and execute C directly execute D execute while compiling

12. The token of the Python language statement block is ( C )

A semicolon B comma C indent D /

13. The following is the method of converting characters into bytes (B)

A decode() B encode() C upper() D rstrip()

14. The following is the correct string (BD)

A ‘abc”ab” B ‘abc”ab’ C “abc”ab” D “abc\”ab”

15. "ab"+"c"*2 The result is: (C)

A abc2 B abcabc C abcc D ababcc

16. Which of the following will be wrong (B)

A 'Beijing'.encode()

B 'Beijing'.decode()

C 'Beijing'.encode().decode()

D above will not be wrong

17. As follows:

str1 = “Runoob example…wow!!!”

str2 = “exam”;

Print(str1.find(str2, 5)) prints the result (B)

A 6 B 7 C 8 D -1

18. The following descriptions of count(), index(), find() methods are wrong (BC)

A count() method is used to count the number of occurrences of a character in a string

B The find() method detects whether the string contains a substring str If it contains a substring, return the starting index value, otherwise an exception will be reported

The C index() method detects whether the substring str is contained in the string, and returns -1 if str is not present

All of the above are wrong

19. There is the following program segment

if k<=10 and k >0:

if k >5:

if k>8:

x=0

else:

X=1

else:

if k>2:

x=3

else:

x=4

Where k takes that set of values ​​x =3 (A)

A 3,4,5 B 3,4 C 5,6,7 D 4,5

20. The following is not a keyword in python (D)

A raise B with C import D final

21. The value returned by calling the following function (D)
def myfun():

pass

A 0 B error cannot run C empty string D None

22. The function is as follows:

def showNnumber(numbers):

for n in numbers:

print(n)

The following will report an error when calling the function (C)

A showNumer([2,4,5]) B showNnumber(‘abcesf’)

C showNnumber(3.4) D showNumber((12,4,5))

23. The function is as follows

def chanageInt(number2):

number2 = number2+1

print("changeInt: number2= ",number2)

#transfer

number1 = 2

changeInt(number1)

print(“number:”,number1)

Which of the printed results is correct ( B )

A changeInt: number2= 3 number: 3

B changeInt: number2= 3 number: 2

C number: 2 changeInt: number2= 2

D number: 2 changeInt: number2= 3

24. The function is as follows

def chanageList(list):

list.append(" end")

print(“list”,list)

#transfer

strs =[‘1’,‘2’]

changeList(strs)

print(“strs”,strs)

The correct output for the value of strs and list below is ( CD )

A strs [‘1’,‘2’] B list [‘1’,‘2’]

C list [‘1’,‘2’,’end’] D strs [‘1’,‘2’,’end’]

25. Define the class as follows:

class Hello():

pass

The error is stated below ( CD )

A The class instance contains the __dir__() method

B This class instance contains the __hash__() method

C This class instance only contains __dir__(), not __hash__()

D This class does not define any methods, so this instance does not contain any methods

26. Define the class as follows:

class hello():

def showInfo(sef):

print(self.x)

Which of the following descriptions is correct (AC)

A This class cannot be instantiated

B This class can be instantiated

C will have a syntax error in the pycharm tool, saying that self is not defined

D This class can be instantiated, and can call showInfo() through the object normally

27. The wrong statement about the python class is (B)

Instance methods of class A must be created before they can be called

The instance method of class B can only be called before the object is created

Class methods of class C can be called with object and class name

Static properties of class D can be called with class name and object

28. Define the class as follows

class Hello():

def __init__(self,name)

self.name=name

def showInfo(self)

print(self.name)

The following code can be executed normally (C)

A h = Hello

h.showInfo()

B h = Hello()

h.showInfo('Zhang San')

C h = Hello('Zhang San')

h.showInfo()

D h = Hello(‘admin’)

29. Define the class as follows:

  class A():
def a():
print(“a”)
class B ():
def b():
print(“b”)
  class C():
def c():
print(c)
  class D(A,C):
def d():
print(“d”)
d = D()
d.a()
d.b()
d.d()

The result of the execution of the following program is (D)

A a,b,d B a,d

C d,a D execution will report an error

30. Which of the following python can start normally (D)

A typo B wrong expression

C indentation error D manually throwing an exception

31. The statement about abnormality is correct (B)

A program throws an exception to terminate the program

Throwing an exception in the B program does not necessarily terminate the program

C typo causes program to terminate

D indentation errors will cause the program to terminate

32. Which of the following programs is wrong (A)

try:

#statement block 1

except IndexError as i:

# statement block 2

A changed the program to handle the exception, so the program will not be terminated

B changed the program to handle exceptions, and it may not be terminated due to exceptions

C statement block 1, if an IndexError exception is thrown, the program will not be terminated due to the exception

D statement block 2 may not be executed

33. The procedure is as follows:

try:
    number = int(input("请输入数字:"))
 print("number:",number)
 print("=======hello======")
except Exception as e:
 # 报错`[错误日志](https://www.zhihu.com/search?q=%E9%94%99%E8%AF%AF%E6%97%A5%E5%BF%97&search_source=Entity&hybrid_search_source=Entity&hybrid_search_extra=%7B%22sourceType%22%3A%22answer%22%2C%22sourceId%22%3A%221643350335%22%7D "错误日志")`
 print("打印异常详情信息: ",e)
else:
 print("没有异常")
finally:#关闭资源
 print("finally")
print("end")

The input is 1a and the result is: ( B )

A number: 1

Print exception details: invalid literal for int() with base 10:

finally

end

B Print exception details: invalid literal for int() with base 10:

finally

end

C hello===

Print exception details: invalid literal for int() with base 10:

finally

End

D above are correct

34. The wrong way to import modules is (D)

A import mo B from mo import *

C import mo as m D import m from mo

35 Which of the following statements about modules is wrong (C)

A An xx.py is a module

B Any normal xx.py file can be imported as a module

The extension of the C module file is not necessarily .py

When D is running, it will search for imported modules from the specified directory, if not, an error will be reported

Two answer question

  1. Please describe the difference between lists and tuples, and cast between them respectively?

The difference between List and tuple

difference:

1. The way of definition

list[] tuple()

2. Is it variable

list mutable tuple() immutable

3. There are append() and insert() functions in list, but not in tuple

Same point:

are ordered collections (containers)

Convert List to tuple:

temp_list = [1,2,3,4,5]

Cast temp_list: tuple(temp_list)

Convert tuple to list:

temp_tuple = (1,2,3)

The method is similar, and it can also be cast: list(temp_tuple

2. What are the rules for defining functions?

  • A function code block begins with the def keyword, followed by the function identifier name and parentheses **()**.
  • Any incoming parameters and arguments must be enclosed in parentheses. Parameters can be defined between parentheses.
  • The first statement of the function can optionally use a docstring - used to store the function description.
  • Function content starts with a colon and is indented.
  • return [expression] Terminates the function, optionally returning a value to the caller. return without an expression is equivalent to returning None.

3. What is the difference between __new__ and __init__?

  1. __new__ is a static method and __init__ is an instance method.
  2. The __new__ method returns a created instance, while __init__ returns nothing.
  3. The following __init__ can only be called when __new__ returns an instance of cls.
  4. __new__ is called when a new instance is created, and __init__ is used when an instance is initialized.

4. What is the difference between read, readline and readlines ?

read reads the entire file

readline reads the next line, using the generator method

readlines reads the entire file into an iterator for us to iterate over

5. Remove duplicate elements in old_list = [1,1,1,3,4]
new_list = list(set(old_list))

6. Construct a dict with a list that has a correspondence between two elements

names = [‘jianpx’, ‘yue’]
ages = [23, 40]
m = dict(zip(names,ages))

Three programming questions

1. Use the nesting of conditional operators to complete this question: students with academic scores >= 90 points are represented by A, those with scores between 60 and 89 are represented by B, and students with scores below 60 are represented by C

def main():
    s = int(input('请输入成绩:'))
    if s>=90:
        grade = 'A'
    elif s>=60:
        grade = 'B'
    else:
        grade = 'C'
    print grade,
  main()

2. Enter a line of characters, and count the number of English letters, spaces, numbers and other characters in it.

def main():
    s = input('input a string:')
    letter = 0 #统计字母
    space = 0#`[统计空格](https://www.zhihu.com/search?q=%E7%BB%9F%E8%AE%A1%E7%A9%BA%E6%A0%BC&search_source=Entity&hybrid_search_source=Entity&hybrid_search_extra=%7B%22sourceType%22%3A%22answer%22%2C%22sourceId%22%3A%221643350335%22%7D "统计空格")`
    digit = 0 #统计数字
    other = 0 #统计其他字符
    for c in s:
        if c.isalpha():
            letter+=1
        elif c.isspace():
            space+=1
        elif c.isdigit():
            digit+=1
        else:
            other+=1
print(“字母:”,letter,”空格:”,space,”数字:”,digit,”其他字符:”,other)
    main()

3. Sort 10 numbers

l = []
for i in range(10):
    l.append(int(input('Input a number:')))
#可以直接使用sort函数:l.sort()
#也可以自己写排序代码(选择排序)
for i in range(9):
    for j in range(i+1,10):
        if l[j]<l[i]:
            temp = l[j]
            l[j] = l[i]
            l[i] = temp    
print l
2,4,6,7,8,9,3,1,4

Finally, I will introduce a complete python learning route, from entry to advanced, including mind maps, classic books, and supporting videos, to help those who want to learn python and data analysis!

1. Introduction to Python

The following content is the basic knowledge necessary for all application directions of Python. If you want to do crawlers, data analysis or artificial intelligence, you must learn them first. Anything tall is built on primitive foundations. With a solid foundation, the road ahead will be more stable.

Include:

Computer Basics

insert image description here

python basics

insert image description here

Python introductory video 600 episodes:

Watching the zero-based learning video is the fastest and most effective way to learn. Following the teacher's ideas in the video, it is still very easy to get started from the basics to the in-depth.

2. Python crawler

As a popular direction, reptiles are a good choice whether it is a part-time job or as an auxiliary skill to improve work efficiency.

Relevant content can be collected through crawler technology, analyzed and deleted to get the information we really need.

This information collection, analysis and integration work can be applied in a wide range of fields. Whether it is life services, travel, financial investment, product market demand of various manufacturing industries, etc., crawler technology can be used to obtain more accurate and effective information. use.

insert image description here

Python crawler video material

insert image description here

3. Data analysis

According to the report "Digital Transformation of China's Economy: Talents and Employment" released by the School of Economics and Management of Tsinghua University, the gap in data analysis talents is expected to reach 2.3 million in 2025.

With such a big talent gap, data analysis is like a vast blue ocean! A starting salary of 10K is really commonplace.

insert image description here

4. Database and ETL data warehouse

Enterprises need to regularly transfer cold data from the business database and store it in a warehouse dedicated to storing historical data. Each department can provide unified data services based on its own business characteristics. This warehouse is a data warehouse.

The traditional data warehouse integration processing architecture is ETL, using the capabilities of the ETL platform, E = extract data from the source database, L = clean the data (data that does not conform to the rules), transform (different dimension and different granularity of the table according to business needs) calculation of different business rules), T = load the processed tables to the data warehouse incrementally, in full, and at different times.

insert image description here

5. Machine Learning

Machine learning is to learn part of the computer data, and then predict and judge other data.

At its core, machine learning is "using algorithms to parse data, learn from it, and then make decisions or predictions about new data." That is to say, a computer uses the obtained data to obtain a certain model, and then uses this model to make predictions. This process is somewhat similar to the human learning process. For example, people can predict new problems after obtaining certain experience.

insert image description here

Machine Learning Materials:

insert image description here

6. Advanced Python

From basic grammatical content, to a lot of in-depth advanced knowledge points, to understand programming language design, after learning here, you basically understand all the knowledge points from python entry to advanced.

insert image description here

At this point, you can basically meet the employment requirements of the company. If you still don’t know where to find interview materials and resume templates, I have also compiled a copy for you. It can really be said to be a systematic learning route for nanny and .

insert image description here
But learning programming is not achieved overnight, but requires long-term persistence and training. In organizing this learning route, I hope to make progress together with everyone, and I can review some technical points myself. Whether you are a novice in programming or an experienced programmer who needs to be advanced, I believe that everyone can gain something from it.

It can be achieved overnight, but requires long-term persistence and training. In organizing this learning route, I hope to make progress together with everyone, and I can review some technical points myself. Whether you are a novice in programming or an experienced programmer who needs to be advanced, I believe that everyone can gain something from it.

Data collection

This full version of the full set of Python learning materials has been uploaded to the official CSDN. If you need it, you can click the CSDN official certification WeChat card below to get it for free ↓↓↓ [Guaranteed 100% free]

insert image description here

Good article recommended

Understand the prospect of python: https://blog.csdn.net/SpringJavaMyBatis/article/details/127194835

Learn about python's part-time sideline: https://blog.csdn.net/SpringJavaMyBatis/article/details/127196603

insert image description here

Guess you like

Origin blog.csdn.net/weixin_49892805/article/details/130677555