wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Câu hỏi về danh sách trong Python

Total questions: 110

Worksheet time: 3600secs

Name
Class
Date
1.

Trong Python, loại dữ liệu nào được sử dụng để lưu trữ một danh sách các phần tử?

a)

int

b)

list

c)

tuple

d)

dict

2.

Để khai báo một danh sách rỗng trong Python, cú pháp nào được sử dụng?

a)

list = {}

b)

list = []

c)

list = ()

d)

list = ''

3.

Danh sách trong Python có đặc điểm gì?

a)

Không thể thay đổi giá trị sau khi khai báo

b)

Có thể chứa các phần tử của các kiểu dữ liệu khác nhau

c)

Không thể chứa các phần tử trùng lặp

d)

Chỉ chứa các số nguyên

4.

Cho danh sách: numbers = [2, 4, 6, 8] in ra numbers[1] Kết quả của đoạn mã trên là gì?

a)

2

b)

4

c)

6

d)

8

5.

Cho danh sách: fruits = ["apple", "banana", "cherry"] fruits.append("orange") print(fruits) Sau khi chạy chương trình, danh sách fruits trông như thế nào?

a)

["apple", "banana", "cherry"]

b)

["apple", "banana", "cherry", "orange"]

c)

["apple", "banana"]

d)

["orange", "apple", "banana", "cherry"]

6.

Làm thế nào bạn có thể truy cập hoặc thay đổi giá trị của từng phần tử trong một danh sách?

a)

vị trí

b)

danh sách

c)

chỉ số

d)

độ dài

7.

Cú pháp nào được sử dụng để lặp qua tất cả các phần tử của một danh sách bằng cách sử dụng độ dài (len)?

a)

for i in range(len(list))

b)

for i in range(len(list))

c)

for i in len((list) - 1)

d)

for i in len(list)

8.

Cho danh sách S=[2, 3, 4, 5], làm thế nào để thêm phần tử 1 vào đầu danh sách?

a)

S.append(1)

b)

S=[1]+S

c)

S.append(0,1)

d)

S=S+[1]

9.

Cho A=[1, 2, 3, 4, 5] để biến A=[1, 2, 4, 5], lệnh nào nên được thực thi?

a)

del A[0]

b)

del A[1]

c)

del A[2]

d)

del A[3]

10.

Cho chương trình sau: A=[1, 2, 3, 4, 5] S=0 cho i trong khoảng(len(A) - 1): S=S+A[i] in ra(S) Giá trị của S sẽ là gì?

a)

15

b)

5

c)

0

d)

10

11.

Cú pháp hợp lệ để khai báo một danh sách trong Python là gì?

a)

danh_sach = [1, 2, 3, 4]

b)

danh_sach = (1, 2, 3, 4)

c)

danh_sach = {1, 2, 3, 4}

d)

danh_sach = <1, 2, 3, 4>

12.

Phép toán nào có thể được sử dụng để nối hai danh sách trong Python?

a)

+

b)

-

c)

*

d)

/

13.

Làm thế nào để truy cập phần tử thứ ba trong danh sách my_list = [10, 20, 30]?

4 lines
14.

Phép toán nào dưới đây có thể được sử dụng để nối hai danh sách trong Python?

a)

+

b)

-

c)

*

d)

/

15.

Làm thế nào để truy cập phần tử thứ ba trong danh sách my_list = [10, 20, 30, 40, 50]?

a)

my_list(2)

b)

my_list[2]

c)

my_list[3]

d)

my_list{2}

16.

Cách đúng để thêm một phần tử vào danh sách trong Python là gì?

a)

list.add(6)

b)

list.push(6)

c)

list.insert(6)

d)

list.append(6)

17.

Kết quả của đoạn mã sau đây là gì?

a)

[10, 20, 30, 50]

b)

[10, 20, 30, 40, 50]

c)

[50, 10, 20, 30, 40]

d)

[10, 20, 30, 40]

18.

Kết quả của đoạn mã sau là gì?

a)

Lỗi

b)

4

c)

5

d)

6

19.

Kết quả của đoạn mã sau là gì?

a)

[1, 2, 3, 4, 5]

b)

[4, 5]

c)

[1, 2, 3] + [4, 5]

d)

[1, 2, 3]

20.

Chỉ số của một phần tử trong danh sách Python bắt đầu từ đâu?

a)

-1

b)

0

c)

1

d)

2

21.

Trong Python, kiểu dữ liệu danh sách được biểu diễn như thế nào?

a)

<>

b)

{}

c)

()

d)

[]

22.

Cách đúng để xóa phần tử có giá trị 30 khỏi danh sách my_list = [10, 20, 30, 40, 50] là gì?

a)

my_list.delete(30)

b)

my_list.remove(30)

c)

del my_list(30)

d)

my_list.pop(30)

23.

Kết quả của chương trình sau đây là gì?

a)

[1, 3, 9, 5, 7]

b)

[1, 9, 3, 5, 7]

c)

[1, 3, 5, 7, 9]

d)

[9, 1, 3, 5, 7]

24.

Cho danh sách sau: nums = [10, 20, 30, 40, 50], kết quả của đoạn mã nums.remove(20) sẽ là gì?

a)

[10, 20, 30, 40, 50]

b)

[10, 20, 40, 50]

c)

[10, 20, 30, 50]

d)

[10, 30, 40, 50]

25.

Hàm remove(x) trong danh sách Python có tác dụng gì?

a)

Xóa tất cả các phần tử có giá trị x khỏi danh sách

b)

Xóa phần tử đầu tiên có giá trị x khỏi danh sách

c)

Xóa phần tử tại vị trí x trong danh sách

d)

Xóa toàn bộ danh sách

26.

Hàm insert(i, x) trong danh sách Python có tác dụng gì?

a)

Chèn giá trị x vào đầu danh sách

b)

Chèn giá trị x vào vị trí i trong danh sách

c)

Xóa giá trị x tại vị trí i

d)

Thay thế phần tử tại vị trí i bằng x

27.

Để xóa tất cả các phần tử trong danh sách numbers, lệnh nào nên được sử dụng?

a)

numbers.remove()

b)

numbers.clear()

c)

del numb

28.

Lệnh nào được sử dụng để xóa tất cả các phần tử khỏi danh sách numbers?

a)

numbers.remove()

b)

numbers.clear()

c)

del numbers[0]

d)

clear.number()

29.

Kết quả của đoạn mã sau là gì? nums = [5, 10, 15, 20] nums.insert(1, 7) nums.remove(10) print(nums)

a)

[5, 7, 10, 15, 20]

b)

[5, 7, 15, 20]

c)

[5, 10, 7, 15, 20]

d)

[5, 15, 20]

30.

Sau khi xóa tất cả các phần tử, điều gì sẽ xảy ra với danh sách?

a)

Danh sách biến mất

b)

Danh sách mất phần tử đầu tiên

c)

Danh sách mất phần tử cuối cùng

d)

Danh sách sẽ trở thành một danh sách rỗng

31.

Đối với A=[1, 2, 3, 4, 5], kết quả của lệnh 3 in sẽ là gì?

a)

Lỗi

b)

Sai

c)

Đúng

d)

1

32.

Điều gì sẽ xảy ra nếu gọi remove() trên một phần tử không có trong danh sách?

a)

Danh sách sẽ không thay đổi

b)

Danh sách sẽ bị xóa hoàn toàn

c)

Một lỗi sẽ được phát sinh

d)

Danh sách sẽ mất phần tử đầu tiên

33.

Đối với danh sách A=[1, 2, 3, 4, 5], điều gì sẽ xảy ra sau khi thực hiện lệnh insert(-1,6)?

a)

Gây ra lỗi

b)

Chèn 6 vào cuối A

c)

Chèn 6 vào đầu A

d)

Chèn -1 vào cuối A

34.

Nhập lệnh nào được sử dụng để đếm số lần xuất hiện của một phần tử trong danh sách?

a)

A.danh_sách.find(x)

b)

B.danh_sách.count(x)

c)

C.danh_sách.search(x)

d)

D.danh_sách.index(x)

35.

Kết quả của đoạn mã sau là gì? A.[1, 2, 3, 4]

a)

B.[4, 3, 2, 1]

b)

C.Lỗi.

c)

D.[3, 1, 4, 2]

36.

Nhập lệnh nào được sử dụng để thêm một phần tử vào cuối danh sách trong Python?

a)

A.danh_sách.insert(x)

b)

B.danh_sách.add(x)

c)

C.danh_sách.append(x)

d)

D.danh_sách.push(x)

37.

Kết quả của đoạn mã sau là gì?

a)

A.["a", "b", "c", "x"]

b)

B.["a", "x", "b", "c"]

c)

C.["x", "a", "b", "c"]

d)

D.["a", "b", "x", "c"]

38.

Nhập lệnh nào được sử dụng để sắp xếp một danh sách theo thứ tự tăng dần?

a)

A.list.order()

b)

B.list.sorted()

c)

C.list.sort()

d)

D.sort(list)

39.

Hàm list.pop(x) làm gì?

a)

Xóa phần tử có giá trị x.

b)

Xóa phần tử tại vị trí x.

c)

Xóa toàn bộ danh sách.

d)

Thêm phần tử x vào danh sách.

40.

Hàm list.reverse() làm gì?

a)

Đảo ngược thứ tự các phần tử trong danh sách.

b)

Sắp xếp danh sách theo thứ tự ngược lại.

c)

Xóa

41.

Hàm list.reverse() có tác dụng gì?

a)

Đảo ngược thứ tự các phần tử trong danh sách.

b)

Sắp xếp danh sách theo thứ tự ngược lại.

c)

Xóa toàn bộ danh sách.

d)

Thêm một phần tử vào đầu danh sách.

42.

Lệnh nào được sử dụng để xóa một phần tử theo giá trị trong danh sách?

a)

del list[x]

b)

list.pop(x)

c)

list.remove(x)

d)

list.delete(x)

43.

Kết quả của đoạn mã sau là gì?

a)

[10, 20, 40]

b)

[20, 30, 40]

c)

[10, 30, 40]

d)

[10, 20, 30]

44.

Kết quả của đoạn mã sau là gì?

a)

[1, 2, 3]

b)

[4, 1, 2, 3]

c)

[1, 2, 3, 4]

d)

[1, 2, 3, [4]]

45.

Trong Python, kiểu dữ liệu nào được sử dụng để đại diện cho một chuỗi?

a)

danh sách

b)

chuỗi

c)

Tuple

d)

dict

46.

Để khai báo một chuỗi trong Python, cặp ký hiệu nào có thể được sử dụng?

a)

""

b)

[]

c)

<>

d)

{}

47.

Giống như danh sách, chuỗi có thể:

a)

Lưu trữ nhiều phần tử

b)

Truy cập các phần tử theo chỉ số

c)

Chỉnh sửa từng ký tự trong chuỗi

d)

Thay đổi kích thước một cách động

48.

Kết quả của đoạn mã sau là gì?

a)

t

b)

y

c)

h

d)

o

49.

Điểm khác biệt giữa danh sách và chuỗi là gì?

a)

Danh sách có thể chứa các kiểu dữ liệu khác nhau, trong khi chuỗi chỉ chứa các ký tự.

b)

Các phần tử của danh sách không thể thay đổi, trong khi chuỗi có thể.

c)

Danh sách có thể chứa số, trong khi chuỗi không thể.

d)

Danh sách có thể truy cập từng phần tử, trong khi chuỗi không thể.

50.

Kết quả của chương trình sau đây là gì?

a)

Xin chào

b)

Xin chào Thế giới

c)

Xin chàoThế giới

d)

Lỗi

51.

Given the string s="Nguyễn Văn A", which of the following is not a substring of s?

a)

""

b)

"A"

c)

"Vân"

d)

"Nguyễn"

52.

What will happen if we run the following program?

a)

Jython

b)

Python

c)

Error

d)

J

53.

What is the syntax for iterating by index?

a)

for ch in string

b)

for ch.string()

c)

for i in range (string)

d)

for i in range (len(string))

54.

How many similarities are there between lists and strings?

a)

1

b)

2

c)

3

d)

4

55.

In Python, the index of a character in a string starts from which number?

a)

2

b)

-1

c)

0

d)

1

56.

In Python, a string is represented by which character?

4 lines
57.

How many similarities are there between a list and a string?

a)

1

b)

2

c)

3

d)

4

58.

In Python, what is the starting index of a character in a string?

a)

2

b)

-1

c)

0

d)

1

59.

Which command is used to replace a character in a string?

a)

s.change(old, new)

b)

s.update(old, new)

c)

s.replace(old, new)

d)

s.modify(old, new)

60.

Which is a valid way to declare a string in Python?

a)

s = (Hello)

b)

s = ["Hello"]

c)

s = Hello

d)

s = "Hello"

61.

What is the result of the following code?

a)

y

b)

h

c)

P

d)

T

62.

What is the result of the following code?

a)

L

b)

H

c)

e

d)

o

63.

What does the command s.upper() do?

a)

Converts all characters in the string to lowercase.

b)

Removes whitespace in the string.

c)

Converts all characters in the string to uppercase.

d)

Returns the length of the string.

64.

What does the command len(s) do in Python?

a)

Reverses the string s.

b)

Deletes the string s.

c)

Returns the last character in the string s.

d)

Returns the number of characters in the string s.

65.

Which operation can be used to concatenate two strings in Python?

a)

-

b)

+

c)

*

d)

/

66.

What is the result of the following code?

a)

tho

b)

Tho

c)

Yth

d)

hon

67.

What is the result of the following program?

a)

['Hello', 'World']

b)

['H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd']

c)

HelloWorld

d)

['Hello World']

68.

With which data type is the split() method used?

a)

list

b)

string

c)

int

d)

dict

69.

What does the join() method do?

a)

Combines multiple lists into one list

b)

Joins elements of a list into a string

c)

Joins two lists by merging each element

d)

Converts a list into an integer

70.

What does the split() method do?

a)

Combines multiple lists into one list

b)

Splits elements of a list into a string

c)

Splits elements of a string into a list

d)

Converts a list into an integer

71.

What does the find(sub) method do in Python?

a)

Returns the first position of the substring sub in the original string

b)

Returns the number of occurrences of sub in the original string

72.

What does the find(sub) method do in Python?

a)

Returns the first position of the substring sub in the original string

b)

Returns the number of occurrences of sub in the original string

c)

Deletes sub from the original string

d)

Replaces sub with another string

73.

If find() does not find the substring in the original string, what is the return value?

a)

0

b)

-1

c)

None

d)

Error

74.

What is the result of the following code? s = "Hello World" print(s.find("o"))

a)

4

b)

5

c)

7

d)

Error

75.

What is the result of the following code? s = "Python programming" print(s.find("pro"))

a)

8

b)

0

c)

7

d)

-1

76.

What is the result of the following code? s = "Data Science" print(s.find("z"))

a)

-1

b)

0

c)

10

d)

Error

77.

For the following code: s="Kiểm tra thường xuyên" A=s.split() print(len(A)) What is the output?

a)

1

b)

0

c)

4

d)

3

78.

Which command is used to convert all characters in a string to uppercase?

a)

A.s.lower()

b)

B.s.title()

c)

C.s.capitalize()

d)

D.s.upper()

79.

What is the result of the following code? hello world HELLO WORLD hELLO wORLD Hello World

a)

hello world

b)

HELLO WORLD

c)

hELLO wORLD

d)

Hello World

80.

Which command is used to remove whitespace from the beginning and end of a string?

a)

A.s.strip()

b)

B.s.rstrip()

c)

C.s.replace(" ", "")

d)

D.s.lstrip()

81.

Which command is used to replace a substring in a string?

a)

A.s.replace(old, new)

b)

B.s.update(old, new)

c)

C.s.modify(old, new)

d)

D.s.change(old, new)

82.

What is the result of the following code? "hello world" "hELLO wORLD" "HELLO WORLD" "Hello World"

a)

"hello world"

b)

"hELLO wORLD"

c)

"HELLO WORLD"

d)

"Hello World"

83.

What does the command s.find(x) do?

a)

Creates a copy of s.

b)

Replaces x in s with another value.

c)

Returns the first index of x in s.

d)

Deletes x from s.

84.

Which command returns the number of occurrences of a character or substring in a string?

a)

A.s.index(x)

b)

B.s.find(x)

c)

C.s.count(x)

d)

D.s.match(x)

85.

What is the result of the following code? " Python" "Python " C."Python" D." Python "

a)

" Python"

b)

"Python "

c)

C."Python"

d)

D." Python "

86.

Which command is used to check if a string starts with a certain substring?

a)

A.s.find(x)

b)

B.s.startswith(x)

c)

C.s.endswith(x)

d)

D.s.match(x)

87.

What is the result of the following code?

a)

A.["apple,", "banana,", "cherry"]

b)

B.["apple", "banana",

88.

Does s start with a certain substring?

a)

s.find(x)

b)

s.startswith(x)

c)

s.endswith(x)

d)

s.match(x)

89.

What is the result of the following code?

a)

["apple,", "banana,", "cherry"]

b)

["apple", "banana", "cherry"]

c)

["apple banana cherry"]

d)

["apple banana", "cherry"]

90.

What is the result of the following program?

a)

"Hello, " + ten + "!"

b)

"Hello!"

c)

"Hello, Xuan!"

d)

Error in command.

91.

What is the result of the following program?

a)

5.

b)

10.

c)

Error in program.

d)

50.

92.

What is the result of the following program?

a)

5.

b)

float.

c)

Error in program.

d)

int.

93.

What does the following function do?

a)

Returns the sum of two numbers a and b passed in.

b)

Returns two values a and b.

c)

Calculates the sum of two numbers a and b.

d)

Calculates the sum of two numbers a and b and displays it.

94.

Fill in (…) to find the largest number among 3 input numbers:

a)

max < b, max < c.

b)

max <= b, max < c.

c)

max < b, max <= c.

d)

max <= b, max <= c.

95.

What is the result of the following program?

a)

12.

b)

13.

c)

14.

d)

15.

96.

At which line does the following program have an error?

a)

4.

b)

2.

c)

3.

d)

No line has an error.

97.

At which line does the following program have an error?

a)

2.

b)

3.

c)

1.

d)

No error.

98.

At which line does the following program have an error?

a)

1.

b)

2.

c)

3.

d)

4.

99.

What is the result of the following program?

a)

3 * x

b)

Error in function.

c)

my_function

d)

None.

100.

What is the result of the following program: def my_function(x): return 3 * x print(my_function(3)) print(my_function(5)) print(my_function(9))

a)

3, 5, 9.

b)

9, 15, 27.

c)

9, 5, 27.

d)

The program has an error.

101.

What is the result of the following code?

a)

Nothing happens.

b)

Error due to missing parameter.

c)

3

d)

6

102.

What is the result of the following code?

a)

3 + 5

b)

Error due to missing print

c)

Nothing happens.

d)

8

103.

In Python, which keyword is used to define a function?

a)

Function

b)

Define

c)

func

d)

def

104.

What is the result of the following code?

a)

"Hello, world!"

b)

Error due to missing return

c)

say_hello()

d)

Nothing happens.

105.

What type does the print() function in Python belong to?

a)

Function with return value.

b)

User-defined function.

c)

Mathematical function.

d)

Built-in function.

106.

If a function does not have a return statement, what is its return value?

a)

0

b)

Program error.

c)

False

d)

None

107.

How many parameters can a function in Python have?

a)

Maximum of three parameters.

b)

Many parameters.

c)

Maximum of one parameter.

d)

Maximum of two parameters.

108.

In Python, how do parameters and arguments differ?

a)

Parameters are values passed into a function when called, arguments are variables declared in the function.

b)

Python does not distinguish between parameters and arguments.

c)

Parameters and arguments are exactly the same.

d)

Parameters are variables declared in the function, arguments are actual values passed in when calling the function.

109.

Which command below is used to call a function in Python?

a)

execute function_name()

b)

function_name()

c)

run function_name()

d)

call function_name()

110.

In Python, how can a function return multiple values?

a)

Cannot return multiple values.

b)

Return a list or tuple.

c)

Write multiple values in return but not separated.

d)

Use multiple return statements.