Font size
WorksheetsCâu hỏi về danh sách trong Python
Total questions: 110
Worksheet time: 3600secs
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ử?
int
list
tuple
dict
Để khai báo một danh sách rỗng trong Python, cú pháp nào được sử dụng?
list = {}
list = []
list = ()
list = ''
Danh sách trong Python có đặc điểm gì?
Không thể thay đổi giá trị sau khi khai báo
Có thể chứa các phần tử của các kiểu dữ liệu khác nhau
Không thể chứa các phần tử trùng lặp
Chỉ chứa các số nguyên
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ì?
2
4
6
8
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?
["apple", "banana", "cherry"]
["apple", "banana", "cherry", "orange"]
["apple", "banana"]
["orange", "apple", "banana", "cherry"]
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?
vị trí
danh sách
chỉ số
độ dài
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)?
for i in range(len(list))
for i in range(len(list))
for i in len((list) - 1)
for i in len(list)
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?
S.append(1)
S=[1]+S
S.append(0,1)
S=S+[1]
Cho A=[1, 2, 3, 4, 5] để biến A=[1, 2, 4, 5], lệnh nào nên được thực thi?
del A[0]
del A[1]
del A[2]
del A[3]
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ì?
15
5
0
10
Cú pháp hợp lệ để khai báo một danh sách trong Python là gì?
danh_sach = [1, 2, 3, 4]
danh_sach = (1, 2, 3, 4)
danh_sach = {1, 2, 3, 4}
danh_sach = <1, 2, 3, 4>
Phép toán nào có thể được sử dụng để nối hai danh sách trong Python?
+
-
*
/
Làm thế nào để truy cập phần tử thứ ba trong danh sách my_list = [10, 20, 30]?
Phép toán nào dưới đây có thể được sử dụng để nối hai danh sách trong Python?
+
-
*
/
Làm thế nào để truy cập phần tử thứ ba trong danh sách my_list = [10, 20, 30, 40, 50]?
my_list(2)
my_list[2]
my_list[3]
my_list{2}
Cách đúng để thêm một phần tử vào danh sách trong Python là gì?
list.add(6)
list.push(6)
list.insert(6)
list.append(6)
Kết quả của đoạn mã sau đây là gì?
[10, 20, 30, 50]
[10, 20, 30, 40, 50]
[50, 10, 20, 30, 40]
[10, 20, 30, 40]
Kết quả của đoạn mã sau là gì?
Lỗi
4
5
6
Kết quả của đoạn mã sau là gì?
[1, 2, 3, 4, 5]
[4, 5]
[1, 2, 3] + [4, 5]
[1, 2, 3]
Chỉ số của một phần tử trong danh sách Python bắt đầu từ đâu?
-1
0
1
2
Trong Python, kiểu dữ liệu danh sách được biểu diễn như thế nào?
<>
{}
()
[]
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ì?
my_list.delete(30)
my_list.remove(30)
del my_list(30)
my_list.pop(30)
Kết quả của chương trình sau đây là gì?
[1, 3, 9, 5, 7]
[1, 9, 3, 5, 7]
[1, 3, 5, 7, 9]
[9, 1, 3, 5, 7]
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ì?
[10, 20, 30, 40, 50]
[10, 20, 40, 50]
[10, 20, 30, 50]
[10, 30, 40, 50]
Hàm remove(x) trong danh sách Python có tác dụng gì?
Xóa tất cả các phần tử có giá trị x khỏi danh sách
Xóa phần tử đầu tiên có giá trị x khỏi danh sách
Xóa phần tử tại vị trí x trong danh sách
Xóa toàn bộ danh sách
Hàm insert(i, x) trong danh sách Python có tác dụng gì?
Chèn giá trị x vào đầu danh sách
Chèn giá trị x vào vị trí i trong danh sách
Xóa giá trị x tại vị trí i
Thay thế phần tử tại vị trí i bằng x
Để 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?
numbers.remove()
numbers.clear()
del numb
Lệnh nào được sử dụng để xóa tất cả các phần tử khỏi danh sách numbers?
numbers.remove()
numbers.clear()
del numbers[0]
clear.number()
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)
[5, 7, 10, 15, 20]
[5, 7, 15, 20]
[5, 10, 7, 15, 20]
[5, 15, 20]
Sau khi xóa tất cả các phần tử, điều gì sẽ xảy ra với danh sách?
Danh sách biến mất
Danh sách mất phần tử đầu tiên
Danh sách mất phần tử cuối cùng
Danh sách sẽ trở thành một danh sách rỗng
Đối với A=[1, 2, 3, 4, 5], kết quả của lệnh 3 in sẽ là gì?
Lỗi
Sai
Đúng
1
Đ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?
Danh sách sẽ không thay đổi
Danh sách sẽ bị xóa hoàn toàn
Một lỗi sẽ được phát sinh
Danh sách sẽ mất phần tử đầu tiên
Đố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)?
Gây ra lỗi
Chèn 6 vào cuối A
Chèn 6 vào đầu A
Chèn -1 vào cuối A
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.danh_sách.find(x)
B.danh_sách.count(x)
C.danh_sách.search(x)
D.danh_sách.index(x)
Kết quả của đoạn mã sau là gì? A.[1, 2, 3, 4]
B.[4, 3, 2, 1]
C.Lỗi.
D.[3, 1, 4, 2]
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.danh_sách.insert(x)
B.danh_sách.add(x)
C.danh_sách.append(x)
D.danh_sách.push(x)
Kết quả của đoạn mã sau là gì?
A.["a", "b", "c", "x"]
B.["a", "x", "b", "c"]
C.["x", "a", "b", "c"]
D.["a", "b", "x", "c"]
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.list.order()
B.list.sorted()
C.list.sort()
D.sort(list)
Hàm list.pop(x) làm gì?
Xóa phần tử có giá trị x.
Xóa phần tử tại vị trí x.
Xóa toàn bộ danh sách.
Thêm phần tử x vào danh sách.
Hàm list.reverse() làm gì?
Đảo ngược thứ tự các phần tử trong danh sách.
Sắp xếp danh sách theo thứ tự ngược lại.
Xóa
Hàm list.reverse() có tác dụng gì?
Đảo ngược thứ tự các phần tử trong danh sách.
Sắp xếp danh sách theo thứ tự ngược lại.
Xóa toàn bộ danh sách.
Thêm một phần tử vào đầu danh sách.
Lệnh nào được sử dụng để xóa một phần tử theo giá trị trong danh sách?
del list[x]
list.pop(x)
list.remove(x)
list.delete(x)
Kết quả của đoạn mã sau là gì?
[10, 20, 40]
[20, 30, 40]
[10, 30, 40]
[10, 20, 30]
Kết quả của đoạn mã sau là gì?
[1, 2, 3]
[4, 1, 2, 3]
[1, 2, 3, 4]
[1, 2, 3, [4]]
Trong Python, kiểu dữ liệu nào được sử dụng để đại diện cho một chuỗi?
danh sách
chuỗi
Tuple
dict
Để khai báo một chuỗi trong Python, cặp ký hiệu nào có thể được sử dụng?
""
[]
<>
{}
Giống như danh sách, chuỗi có thể:
Lưu trữ nhiều phần tử
Truy cập các phần tử theo chỉ số
Chỉnh sửa từng ký tự trong chuỗi
Thay đổi kích thước một cách động
Kết quả của đoạn mã sau là gì?
t
y
h
o
Điểm khác biệt giữa danh sách và chuỗi là gì?
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ự.
Các phần tử của danh sách không thể thay đổi, trong khi chuỗi có thể.
Danh sách có thể chứa số, trong khi chuỗi không thể.
Danh sách có thể truy cập từng phần tử, trong khi chuỗi không thể.
Kết quả của chương trình sau đây là gì?
Xin chào
Xin chào Thế giới
Xin chàoThế giới
Lỗi
Given the string s="Nguyễn Văn A", which of the following is not a substring of s?
""
"A"
"Vân"
"Nguyễn"
What will happen if we run the following program?
Jython
Python
Error
J
What is the syntax for iterating by index?
for ch in string
for ch.string()
for i in range (string)
for i in range (len(string))
How many similarities are there between lists and strings?
1
2
3
4
In Python, the index of a character in a string starts from which number?
2
-1
0
1
In Python, a string is represented by which character?
How many similarities are there between a list and a string?
1
2
3
4
In Python, what is the starting index of a character in a string?
2
-1
0
1
Which command is used to replace a character in a string?
s.change(old, new)
s.update(old, new)
s.replace(old, new)
s.modify(old, new)
Which is a valid way to declare a string in Python?
s = (Hello)
s = ["Hello"]
s = Hello
s = "Hello"
What is the result of the following code?
y
h
P
T
What is the result of the following code?
L
H
e
o
What does the command s.upper() do?
Converts all characters in the string to lowercase.
Removes whitespace in the string.
Converts all characters in the string to uppercase.
Returns the length of the string.
What does the command len(s) do in Python?
Reverses the string s.
Deletes the string s.
Returns the last character in the string s.
Returns the number of characters in the string s.
Which operation can be used to concatenate two strings in Python?
-
+
*
/
What is the result of the following code?
tho
Tho
Yth
hon
What is the result of the following program?
['Hello', 'World']
['H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd']
HelloWorld
['Hello World']
With which data type is the split() method used?
list
string
int
dict
What does the join() method do?
Combines multiple lists into one list
Joins elements of a list into a string
Joins two lists by merging each element
Converts a list into an integer
What does the split() method do?
Combines multiple lists into one list
Splits elements of a list into a string
Splits elements of a string into a list
Converts a list into an integer
What does the find(sub) method do in Python?
Returns the first position of the substring sub in the original string
Returns the number of occurrences of sub in the original string
What does the find(sub) method do in Python?
Returns the first position of the substring sub in the original string
Returns the number of occurrences of sub in the original string
Deletes sub from the original string
Replaces sub with another string
If find() does not find the substring in the original string, what is the return value?
0
-1
None
Error
What is the result of the following code? s = "Hello World" print(s.find("o"))
4
5
7
Error
What is the result of the following code? s = "Python programming" print(s.find("pro"))
8
0
7
-1
What is the result of the following code? s = "Data Science" print(s.find("z"))
-1
0
10
Error
For the following code: s="Kiểm tra thường xuyên" A=s.split() print(len(A)) What is the output?
1
0
4
3
Which command is used to convert all characters in a string to uppercase?
A.s.lower()
B.s.title()
C.s.capitalize()
D.s.upper()
What is the result of the following code? hello world HELLO WORLD hELLO wORLD Hello World
hello world
HELLO WORLD
hELLO wORLD
Hello World
Which command is used to remove whitespace from the beginning and end of a string?
A.s.strip()
B.s.rstrip()
C.s.replace(" ", "")
D.s.lstrip()
Which command is used to replace a substring in a string?
A.s.replace(old, new)
B.s.update(old, new)
C.s.modify(old, new)
D.s.change(old, new)
What is the result of the following code? "hello world" "hELLO wORLD" "HELLO WORLD" "Hello World"
"hello world"
"hELLO wORLD"
"HELLO WORLD"
"Hello World"
What does the command s.find(x) do?
Creates a copy of s.
Replaces x in s with another value.
Returns the first index of x in s.
Deletes x from s.
Which command returns the number of occurrences of a character or substring in a string?
A.s.index(x)
B.s.find(x)
C.s.count(x)
D.s.match(x)
What is the result of the following code? " Python" "Python " C."Python" D." Python "
" Python"
"Python "
C."Python"
D." Python "
Which command is used to check if a string starts with a certain substring?
A.s.find(x)
B.s.startswith(x)
C.s.endswith(x)
D.s.match(x)
What is the result of the following code?
A.["apple,", "banana,", "cherry"]
B.["apple", "banana",
Does s start with a certain substring?
s.find(x)
s.startswith(x)
s.endswith(x)
s.match(x)
What is the result of the following code?
["apple,", "banana,", "cherry"]
["apple", "banana", "cherry"]
["apple banana cherry"]
["apple banana", "cherry"]
What is the result of the following program?
"Hello, " + ten + "!"
"Hello!"
"Hello, Xuan!"
Error in command.
What is the result of the following program?
5.
10.
Error in program.
50.
What is the result of the following program?
5.
float.
Error in program.
int.
What does the following function do?
Returns the sum of two numbers a and b passed in.
Returns two values a and b.
Calculates the sum of two numbers a and b.
Calculates the sum of two numbers a and b and displays it.
Fill in (…) to find the largest number among 3 input numbers:
max < b, max < c.
max <= b, max < c.
max < b, max <= c.
max <= b, max <= c.
What is the result of the following program?
12.
13.
14.
15.
At which line does the following program have an error?
4.
2.
3.
No line has an error.
At which line does the following program have an error?
2.
3.
1.
No error.
At which line does the following program have an error?
1.
2.
3.
4.
What is the result of the following program?
3 * x
Error in function.
my_function
None.
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))
3, 5, 9.
9, 15, 27.
9, 5, 27.
The program has an error.
What is the result of the following code?
Nothing happens.
Error due to missing parameter.
3
6
What is the result of the following code?
3 + 5
Error due to missing print
Nothing happens.
8
In Python, which keyword is used to define a function?
Function
Define
func
def
What is the result of the following code?
"Hello, world!"
Error due to missing return
say_hello()
Nothing happens.
What type does the print() function in Python belong to?
Function with return value.
User-defined function.
Mathematical function.
Built-in function.
If a function does not have a return statement, what is its return value?
0
Program error.
False
None
How many parameters can a function in Python have?
Maximum of three parameters.
Many parameters.
Maximum of one parameter.
Maximum of two parameters.
In Python, how do parameters and arguments differ?
Parameters are values passed into a function when called, arguments are variables declared in the function.
Python does not distinguish between parameters and arguments.
Parameters and arguments are exactly the same.
Parameters are variables declared in the function, arguments are actual values passed in when calling the function.
Which command below is used to call a function in Python?
execute function_name()
function_name()
run function_name()
call function_name()
In Python, how can a function return multiple values?
Cannot return multiple values.
Return a list or tuple.
Write multiple values in return but not separated.
Use multiple return statements.
