Page 245 - Ai_V3.0_c11_flipbook
P. 245
4. What is an example of a valid identifier in Python?
a. 1variable b. my-variable
c. calculate_sum d. my@var
5. Identify the relational operator from the following:
a. and b. +
c. >= d. **
6. What is the type of the variable x after the following code executes?
x = None
a. int b. float
c. None d. bool
7. What will be the output of the following code?
for i in range(1, 6):
if i == 3:
continue
print("Iteration:", i)
a. Iteration: 1 Iteration: 2 Iteration: 3 Iteration: 4 Iteration: 5
b. Iteration: 1 Iteration: 2 Iteration: 4 Iteration: 5
c. Iteration: 1 Iteration: 2
d. Iteration: 3 Iteration: 4 Iteration: 5
8. Which of the functions read the contents of the CSV file line by line?
a. csv.reader() b. csv.read()
c. csv.readers() d. csv.reads()
9. What does the following code do?
import csv
with open('Customer.csv', 'a', newline='') as file:
writer = csv.writer(file)
writer.writerow(['4', 'Amit', 'Verma', 'Pune'])
a. Reads a CSV file b. Writes a new CSV file
c. Appends a row to an existing CSV file d. Deletes a row from a CSV file
10. What method is used to access a specific element in a DataFrame by its row and column index?
a. .loc[] b. .iloc[]
c. .at[] d. .ix[]
11. Which of the following is the correct code to create a DataFrame using a list of dictionaries?
a. import pandas as pd
data = [{'ID': 1, 'Name': 'Arti', 'Age': 25},
{'ID': 2, 'Name': 'Trinabh', 'Age': 30},
{'ID': 3, 'Name': 'Surbhi', 'Age': 28}]
df = pd.DataFrame(data)
print(df)
Python Programming 243

