Python multiple choice exam questions Daquan

To generate random numbers in Python, you should use ()

A: math module
B: random module
correct answer
C: numpy module
D: pygame module

Which of the following statements about functions is incorrect: ()

A: Functions can have no parameters
B: Functions can have multiple return values
​​Correct answer
C: Functions can have no return statement
D: Functions all have return values

If a = 'abcd', if you want to change a to 'ebcd', the following statement is correct ()

A: a[0] = 'e'
B: a.replace('a', 'e')
C: a[1] = 'e'
D: a = 'e' + “bcd”
correct answer

Below ( ) is not a valid variable name. ()

A: _demo
B: banana
C: Numbr
D: my-scoreCorrect
answer

Suppose there is a file /usr/lib/python/person.py with the following content, what is the output of the following command?

class Person:
  def __init__(self):
    pass
  def getAge(self):
    print(__name__)

p = Person()
p.getAge()

A: Person
B: getAge
C: usr.lib.python.person
D: main
correct answer
E: An exception is thrown

What is the result of running the following code? ()

numbers = [1, 2, 3, 4]
numbers.append([5,6,7,8])
print(len(numbers))

A: 4
B: 5
Correct answer
C: 8
D: 12

Python datatype does not contain ()

A: char
correct answer
B: int
C: float
D: list
8

The execution result of the following code is ()

ls = [[1,2,3],[[4,5],6],[7,8]] 
print(len(ls))

A: 1
B: 3
Correct answer
C: 8
D: 4
9

The data types that Python does not support are

A: char
correct answer
B: int
C: float
D: list
10

Among the following data in different number systems, the one with the largest value is ( )

A: 0x2B
Correct answer
B: 0o37
C: 41
D: 0b100111
1

In the Python programming language, the functions used for input and output are ()

A: read( ) and write( )
B: input( ) and output( )
C: input( ) and print( )
correct answer
D: cin( ) and cout( )
2

To generate random numbers in Python, you should use ()

A: math module
B: random module
correct answer
C: numpy module
D: pygame module

Regarding the description of the following code, the wrong option is (

with open('abc.txt','r+') as f:
  lines = f.readlines()
  for item in lines:
    print(item)

A: After executing the code, the abc.txt file is not closed and must be closed through the close() function
Correct answer
B: Print out the content of the abc.txt file
C: item is a string type
D: lines is a list type

Which of the following statements about functions is incorrect: ()

A: Functions can have no parameters
B: Functions can have multiple return values
​​Correct answer
C: Functions can have no return statement
D: Functions all have return values

If a = 'abcd', if you want to change a to 'ebcd', the following statement is correct ()

A: a[0] = 'e'
B: a.replace('a', 'e')
C: a[1] = 'e'
D: a = 'e' + “bcd”
correct answer

Below ( ) is not a valid variable name. ()

A: _demo
B: banana
C: Numbr
D: my-scoreCorrect
answer

Which of the following statements about the len() function is wrong ( )

A: The len() function can be used to return the number of characters in a string
B: The len() function can be used to return the number of elements in a list
C: The result of len("I love China") is 10
The correct answer
D: The result of len("I love China") is 12

What is the result of running the following code? ()

import math
print math.floor(5.5)

A: 5
B: 5.0
Correct answer
C: 5.5
D: 6

In Python's object-oriented programming, the following description is wrong ()

A: Define the class with class
B: Use the __init__ method to bind attributes
C: Create the corresponding object without defining the class in advance
Correct answer
D: The class contains attributes and methods

Among the following data in different number systems, the one with the largest value is ( )

A: 0x2B
Correct answer
B: 0o37
C: 41
D: 0b100111

To generate random numbers in Python, you should use ()

A: math module
B: random module
correct answer
C: numpy module
D: pygame module
2

The following data types not supported by python are ()

A: char
correct answer
B: float
C: int
D: list
3

"=" in the Python expression a=b means ()

A: Swap the values ​​of the variables on the left and right of "="
B: Assign the value of the variable on the right of "=" to the variable on the left
Correct answer
C: Assign the value of the variable on the left of "=" to the variable on the right
D: Compare the variables on the left and right of "=" Is the value equal to
4

Regarding the description of the following code, the wrong option is ()

with open('abc.txt','r+') as f:
  lines = f.readlines()
  for item in lines:
    print(item)

A: After the code is executed, the abc.txt file is not closed and must be closed through the close() function
Correct answer
B: Print out the content of the abc.txt file
C: item is a string type
D: lines is a list type
5

Run the following program, the output is correct ()

def fun(x,y=2,z=4):
  return x*y+z

a=fun(z=1,y=3,x=4)
print(a)

A: 12
B: 13
Correct answer
C: 6
D: 8

Delete all elements in the list, and the list exists, use the () method

A: del
correct answer
B: remove
C: pop
D: delete

Suppose there is a file /usr/lib/python/person.py with the following content, what is the output of the following command?

class Person:
  def __init__(self):
    pass
  def getAge(self):
    print(__name__)


p = Person()
p.getAge()

A: Person
B: getAge
C: usr.lib.python.person
D: main
correct answer
E: An exception is thrown

Regarding Python memory management, which of the following statements is wrong

A: The variable does not need to be declared in advance
B: The variable can be used directly without being created and assigned first
Correct answer
C: The variable does not need to specify the type
D: You can use del to release resources

In Python's object-oriented programming, the following description is wrong ()

A: Define the class with class
B: Use the __init__ method to bind attributes
C: Create the corresponding object without defining the class in advance
Correct answer
D: The class contains attributes and methods

The following statement that cannot create a dictionary is

A: dict1 = {}
B: dict2 = { 3 : 5 }
C: dict3 = {[1,2,3]: "uestc"}
correct answer
D: dict4 = {(1,2,3): "uestc" }

1

There are the following SQL statements

SELECT * FROM stock WHERE unit price BETWEEN 12.76 AND 15.20 The equivalent of this statement is ()

A: SELECT * FROM stock WHERE unit price<=15.20 AND unit price>=12.76
correct answer
B: SELECT * FROM stock WHERE unit price<15.20 AND unit price>12.76
C: SELECT * FROM stock WHERE unit price<=15.20 AND unit price>12.76
D: SELECT * FROM stock WHERE unit price<15.20 AND unit price>=12.76
2

For the description of the code segment below, the correct one is ( ).

list1 = [[1,2,3],[4,5,6],[7,8,9]]
list2 = [[0,0,0],[0,0,0],[0,0,0]]
for i in range(3):
  for j in range(3):
    list2[j][i] = list1[i][j]

A: The value of list2[2][2] is 5
B: The value of list2[0][1] is 2
C: The value of list2[0][0] is 0
D: The value of list2[1][2] yes 8
correct answer

Run the following program, the output is correct ()

def fun(x,y=2,z=4):
return x*y+z

a=fun(z=1,y=3,x=4)
print(a)
A: 12
B: 13
Correct answer
C: 6
D: 8
4

With SQL, how would you return all records from the "Persons" table in descending order based on the "FirstName" column?

A:SELECT * FROM Persons SORT ‘FirstName’ DESC

B:SELECT * FROM Persons ORDER BY FirstName DESC

Correct answer
C: SELECT * FROM Persons ORDER FirstName DESC

D:SELECT * FROM Persons SORT BY ‘FirstName’ DESC
5

Let s="happy time", then the result of print(s[-2:]) is ( )

A: me
correct answer
B: happy
C: time
D: ha
6

Use the ( ) keyword to create python custom functions. ()

A: function
B: func
C: procedure
D: def
Correct answer
7

In python, use the open method to open a file in binary format for appending, then the access mode is ()

A: rb
B: wb
C: ab
Correct answer
D: a
8

What is the result of running the following code? ()

import math
print math.floor(5.5)
A: 5
B: 5.0
Correct answer
C: 5.5
D: 6
9

Regarding Python memory management, which of the following statements is wrong

A: The variable does not need to be declared in advance
B: The variable can be used directly without being created and assigned first
Correct answer
C: The variable does not need to specify the type
D: You can use del to release resources

The following statement that cannot create a dictionary is

A: dict1 = {}
B: dict2 = { 3 : 5 }
C: dict3 = {[1,2,3]: "uestc"}
correct answer
D: dict4 = {(1,2,3): "uestc" }

Run the following Python program, the result is correct (

a=18
b=7
c=a % b
b=a % b
print(a,b)

A: 18 5
B: 5 18
C: 18 4
Correct answer
D: 4 18
2

In python, which of the following options a has a data type of integer ()

A: a=5Correct
answer
B: a=input()
C: a='5'
D: a=5.0
3

If a = 'abcd', if you want to change a to 'ebcd', the following statement is correct ()

A: a[0] = 'e'
B: a.replace('a', 'e')
C: a[1] = 'e'
D: a = 'e' + “bcd”
correct answer
4

Run the following program, the output is correct ()

def fun(x,y=2,z=4):
  return x*y+z

a=fun(z=1,y=3,x=4)
print(a)

A: 12
B: 13
Correct answer
C: 6
D: 8
5

What is the result of running the following code? ()

numbers = [1, 2, 3, 4]
numbers.append([5,6,7,8])
print (len(numbers))
A: 4
B: 5
Correct Answer
C: 8
D: 12

Let s="happy time", then the result of print(s[-2:]) is ( )

A: me
correct answer
B: happy
C: time
D: ha
7

In python, use the open method to open a file in binary format for appending, then the access mode is ()

A: rb
B: wb
C: ab
Correct answer
D: a
8

There is the following Python program, after executing the program, the result is ( )
g = lambda x,y=3,z=5:x+y+z
print(g(2))
A: 2

B:5

C: 7
D: 10Correct
answer
9

Suppose there is a file /usr/lib/python/person.py with the following content, what is the output of the following command?

class Person:
  def __init__(self):
    pass
  def getAge(self):
    print(__name__)

p = Person()
p.getAge()

A: Person
B: getAge
C: usr.lib.python.person
D: main
correct answer
E: An exception is thrown

In Python's object-oriented programming, the following description is wrong ()

A: Define the class with class
B: Use the __init__ method to bind attributes
C: Create the corresponding object without defining the class in advance
Correct answer
D: The class contains attributes and methods

In python, the statement print(a,b) means ()

A: print a, b
B: output (a, b)
C: output a, b
D: output the value of a, b
Correct answer

In Python, a better way to implement a multi-branch selection structure is ()

A: if
B: if-else
C: if-elif-else
correct answer
D: nested if

To generate random numbers in Python, you should use ()

A: math module
B: random module
correct answer
C: numpy module
D: pygame module

Regarding the description of the following code, the wrong option is ()

with open('abc.txt','r+') as f:
  lines = f.readlines()
  for item in lines:
    print(item)

A: After executing the code, the abc.txt file is not closed and must be closed through the close() function
Correct answer
B: Print out the content of the abc.txt file
C: item is a string type
D: lines is a list type

Run the following code segment, the output result is True, then you can fill in ( )

newdict={"id":"03","name":"Xiaoming","age":17,"grade":[90,94,88]}
print( ① in newdict)

A: 94
B: 17
C: "id"
correct answer
D: "X"

Run the following program, the output is correct ()

def fun(x,y=2,z=4):
  return x*y+z

a=fun(z=1,y=3,x=4)
print(a)

A: 12
B: 13
Correct answer
C: 6
D: 8
7

Define a list num=list(range(3,6)) What is the output of print(num)? ( )

A:[0,1,2,3]

B:[0,1,2,3,4,5,6]

C:[3,4,5]

Correct Answer
D: [3,4,5,6]
8

What is the result of running the following code? ()

names1 = [‘Amir’, ‘Barry’, ‘Chales’, ‘Dao’]
if ‘amir’ in names1:
  print(1)
else:
  print(2)

A: 1
B: 2
Correct answer
C: An exception is thrown
D: Nothing
9

In Python's object-oriented programming, the following description is wrong ()

A: Define the class with class
B: Use the __init__ method to bind attributes
C: You can create the corresponding object without defining the class in advance
Correct answer
D: The class contains attributes and methods
10

Among the following data in different number systems, the one with the largest value is ( )

A: 0x2B
Correct answer
B: 0o37
C: 41
D: 0b100111

In python, which of the following options a has a data type of integer ()

A: a=5Correct
answer
B: a=input()
C: a='5'
D: a=5.0
2

To generate random numbers in Python, you should use ()

A: math module
B: random module
correct answer
C: numpy module
D: pygame module
3

Delete all elements in the list, and the list exists, use the () method

A: del
correct answer
B: remove
C: pop
D: delete
4

Below ( ) is not a valid variable name. ()

A: _demo
B: banana
C: Numbr
D: my-scoreCorrect
answer
5

Use the ( ) keyword to create python custom functions. ()

A: function
B: func
C: procedure
D: def
Correct answer
6

What is the result of running the following code? ()

import math
print math.floor(5.5)
A: 5
B: 5.0
Correct answer
C: 5.5
D: 6
7

Regarding Python memory management, which of the following statements is wrong

A: The variable does not need to be declared in advance
B: The variable can be used directly without being created and assigned first
Correct answer
C: The variable does not need to specify the type
D: You can use del to release resources
8

Pattern search in SQL statement like 'a % ', which of the following results is possible ( )

A: abc
correct answer
B: bac
C: cab
D: cba
9

There is the following Python statement, after executing the statement, the result is ( )

f=lambda x:5
print(f(3))
A: 3
B: no output
C: 5
correct answer
D: None

Which of the following statements about strings is wrong

A: The character should be regarded as a string of length 1
B: The string ends with \0 to mark the end of the string
Correct answer
C: Either single quotes or double quotes can be used to create a string
D: In a triple quote string Can contain special characters such as line feed and carriage return

There are the following SQL statements

SELECT * FROM stock WHERE unit price BETWEEN 12.76 AND 15.20
The equivalent of this statement is ()
A: SELECT * FROM stock WHERE unit price<=15.20 AND unit price>=12.76
The correct answer
B: SELECT * FROM stock WHERE unit price<15.20 AND unit price> 12.76
C: SELECT * FROM stock WHERE unit price<=15.20 AND unit price>12.76
D: SELECT * FROM stock WHERE unit price<15.20 AND unit price>=12.76
2

Which of the following statements about functions is incorrect: ()
A: Functions can have no parameters
B: Functions can have multiple return values
​​Correct answer
C: Functions can have no return statement
D: Functions can all return values
​​3

Use anonymous function to find the smaller number of two numbers, the correct format of the following definition statement is ()

A:result = lambda ‘x,y’: y if x> y else x
B:result = lambda x,y: y if x> y else x
正确答案
C:result = lambda ‘x,y’: x if x> y else y
D:result = lambda x,y: x if x> y else y
4

If a = 'abcd', if you want to change a to 'ebcd', the following statement is correct ()

A: a[0] = 'e'
B: a.replace('a', 'e')
C: a[1] = 'e'
D: a = 'e' + “bcd”
correct answer
5

With SQL, how would you return all records from the "Persons" table in descending order based on the "FirstName" column?

A:SELECT * FROM Persons SORT ‘FirstName’ DESC

B:SELECT * FROM Persons ORDER BY FirstName DESC

Correct answer
C: SELECT * FROM Persons ORDER FirstName DESC

D:SELECT * FROM Persons SORT BY ‘FirstName’ DESC
6

Let s="happy time", then the result of print(s[-2:]) is ( )

A: me
correct answer
B: happy
C: time
D: ha
7

If a = 8, b=15, then the value of a % 3+b//6*(b % a) is ( )

A: 16
Correct Answer
B: 23
C: 27
D: 15
8

What is the result of running the following code? ()

import math
print math.floor(5.5)
A: 5
B: 5.0
Correct answer
C: 5.5
D: 6
9

Suppose there is a file /usr/lib/python/person.py with the following content, what is the output of the following command?

class Person:
  def __init__(self):
    pass
  def getAge(self):
    print(__name__)

p = Person()
p.getAge()

A: Person
B: getAge
C: usr.lib.python.person
D: main
correct answer
E: An exception is thrown

Python datatype does not contain ()

A: char
correct answer
B: int
C: float
D: list

5. (2 points) [Single-choice question] a=1;b=2;a,b=b,a:the values ​​of a and b are () A.1,1
B.1,2
C.2
, 1
correct answer numerical exchange
D.2,2

9. [Single-choice question] Executing the following program will output
Def f1()
X=100
Print(x)
X=+1
F1()
A, ERROR
B, 100
The correct answer
C\101
D, 99

おすすめ

転載: blog.csdn.net/m0_37317411/article/details/124842010