Python Fundamentals Test Questions (with Answers)

1. Multiple choice questions: 2 points for each small question, 40 points in total.

1. Among the following identifier names, the one that conforms to the specification is ( ).

A、 1_a B、 for C、 年龄 D、 a#b

2. Among the following identifiers, the one that is not a data type supported by Python is ( ).

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

3. Among the following options, the option that is not a Python keyword is ( ).

A、 with B、 int C、 del D、 for

4. The result of expressions 3 and 4 is ( ).

A、 3 B、 4 C、 True D、 False

5. The result of the expression eval("500/10") is ( ).

A、 “500/10” B、 500/10 C、 50 D、 50.0

6. It is known that a = "abcdefg", then the value of a[2:4] is ( ).

A、 bc B、 bcd C、 cd D、 cde

7. If you need to split the string, the method you need to use is ( ).

A、 split B、 strip C、 join D、 len

8. If you want to exit the loop, which of the following keywords can be used. ( )

A、 continue B、 pass C、 break D、 exit

9. Given that a = [1, 2, 3, 4, 5], the following options can access element 3 ( )

A、 a[3] B、 a[-3] C、 a[2] D、 a[-2]

10. It is known that a = [i*i for i in range(10)], then the value of a[3] is ( )

A、 3 B、 4 C、 9 D、 16

11. Read the following code, the program execution result is ( )

a = [4, 5, 3, 2, 8]
a.reverse()
print(a)

A、 [4, 5, 3, 2, 8] B、 [8, 2, 3, 5, 4]
C、 [2, 3, 4, 5, 8] D、 [8, 5, 4, 3, 2]

12. For the operation of the list ls, the wrong description in the following options is ( )

A. ls.append(x): Add an element at the end of ls

B. ls.clear(): Delete the last element of ls

C. ls.copy: generate a new list, copy all elements of ls

D. ls.reverse(): All elements of the list ls are reversed

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

A. Characters should be treated as strings of length 1

B. The string ends with the "\0" sign

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

14. Which of the following keywords can be used to define global variables inside a function. ( )

A、 super B、 global C、 static D、 const

15. The following keywords will not be used for module import ( )

A、 import B、 from C、 as D、 with

16. Regarding the exception handling of the program, the error described in the following options is ( )

A. Program exceptions can continue to execute after proper handling

B. Exception statements can be used in conjunction with the else and finally reserved words

Exceptions and errors in C and programming languages ​​are exactly the same concept

D. Python provides exception handling functions through reserved words such as try and except

17. Regarding the function, the wrong description in the following options is ( )

A. The function can complete a specific function, and the use of the function does not need to understand the internal implementation principle

B. The main purpose of using functions is to reduce programming difficulty and code reuse

C, Python use the del keyword to define functions

D. A function is a reusable group of statements with a specific function

18. Which of the following options is not a third-party library for Python data analysis and drawing ( )

A、 numpy B、 pandas C、 matplotlib D、 request

19. When setting the file reading mode, which of the following options can add content at the end of the file. ( )

A、 r B、 w C、 a D、 +

20. To represent the current object in Python, the keyword used is ( )

A、 self B、 super C、 class D、 object

2. Fill in the blanks: 2 points for each small question, 10 points in total.

21. Use ________ in Python for single-line comments.

22. When dividing two integers in Python, the symbol used is _____________.

23. The keyword used by context managers in Python is ________________.

24. In Python, use the built-in _____________ function to get the type of the object.

25. When handling Python exceptions, put the code that may cause exceptions in the _______ statement.

3. Program analysis questions: 5 points for each small question, 20 points in total.

26. Read the following program code. When the user inputs 15 and 35 respectively, the program execution result is _______.

num_1 = input("Please enter the first number: ")
num_2 = input("Please enter the second number: ")
print(num_1 + num_2)

27. Read the following program code, the result of the program execution is ______________.

sum = 0
for i in range(10):
if i // 3 == 2:
continue
sum = sum + i
print(sum)

28. Read the following program code, the result of the program execution is ______________.

i = 1
while i < 6:
i = i + 1
else:
i = i *3
print(i)

29. Read the following program code, the result of the program execution is ______________.

a = 10
b = 20
def fun(temp_a, temp_b): # define function
a, b = temp_b, temp_a
fun(a, b) # call function
print(a) # print result

4. Short answer questions: 7 points for the first question and 8 points for the second question.

30. Briefly describe the selection statement in Python and its usage scenarios.

31. Briefly describe the connection and difference between lists and tuples.

5. Programming questions: 15 points in total.

32. Write a program to realize the sum of all numbers divisible by 7 or including the number 7 between 1 and 100 (including 1 but not including 100).


Information sharing

The complete software testing video learning tutorial below has uploaded the QR code officially certified by CSDN. If you need it, you can get it for free【保证100%免费】

insert image description here

insert image description here

Guess you like

Origin blog.csdn.net/wx17343624830/article/details/128045192