38How do you define a 'group' within a regular expression to extract specific parts?
A.Using {}
B.Using []
C.Using ()
D.Using ||
Correct Answer: Using ()
Explanation:
Parentheses () are used to create capturing groups.
Incorrect! Try again.
39What happens if re.match() does not find a match?
A.Returns None
B.Returns False
C.Raises an error
D.Returns -1
Correct Answer: Returns None
Explanation:
re.match() returns None if no match is found.
Incorrect! Try again.
40In Web Scraping, why might regex be used on HTML content?
A.To connect to the server
B.To execute JavaScript
C.To extract text matching specific patterns
D.To render the page
Correct Answer: To extract text matching specific patterns
Explanation:
Regex is used to parse the raw HTML string and extract specific information like emails, phone numbers, or links.
Incorrect! Try again.
41What is the function os.getcwd() used for?
A.Generate Code Working Directory
B.Get Count Working Directory
C.Get Current Write Directory
D.Get Current Working Directory
Correct Answer: Get Current Working Directory
Explanation:
os.getcwd() returns a string representing the current working directory.
Incorrect! Try again.
42Which method is used to check if a file exists at a specified path?
A.os.check()
B.os.exists()
C.os.path.exists()
D.file.exists()
Correct Answer: os.path.exists()
Explanation:
os.path.exists(path) returns True if the path refers to an existing path or open file descriptor.
Incorrect! Try again.
43To write a list of strings to a file, which method is most direct?
A.write()
B.print()
C.writelines()
D.putlines()
Correct Answer: writelines()
Explanation:
writelines() writes a list of strings to the file.
Incorrect! Try again.
44What does the '$' symbol represent in regex?
A.Start of string
B.End of string
C.Variable
D.Currency
Correct Answer: End of string
Explanation:
The dollar sign '$' matches the end of the string or just before the newline at the end of the string.
Incorrect! Try again.
45Which of the following is NOT a valid file mode?
A.w+
B.z
C.rb
D.ab
Correct Answer: z
Explanation:
'z' is not a standard file opening mode in Python.
Incorrect! Try again.
46If a try block raises an exception that is not defined in the except block, what happens?
A.The program crashes (terminates)
B.The try block repeats
C.It is ignored
D.The else block runs
Correct Answer: The program crashes (terminates)
Explanation:
If an unhandled exception occurs, the program terminates with a traceback error.
Incorrect! Try again.
47Which regex pattern matches any non-digit character?
A.\w
B.\n
C.\D
D.\d
Correct Answer: \D
Explanation:
\D matches any character that is not a decimal digit (inverse of \d).
Incorrect! Try again.
48What is the purpose of the re.split() function?
A.To join strings
B.To find duplicates
C.To remove patterns
D.To split a string by the occurrences of a pattern
Correct Answer: To split a string by the occurrences of a pattern
Explanation:
re.split() splits the string by the occurrences of the pattern.
Incorrect! Try again.
49When using pickle.dump(obj, file), what is the 'file' argument?
A.The file path string
B.A file object opened in binary write mode
C.The directory name
D.A string of data
Correct Answer: A file object opened in binary write mode
Explanation:
The second argument must be a file object (created via open()) capable of writing binary data.
Incorrect! Try again.
50What is the standard Python library used to fetch URLs for web scraping before using regex?
A.os
B.sys
C.urllib
D.pickle
Correct Answer: urllib
Explanation:
urllib (specifically urllib.request) is a standard library used to open URLs to get HTML content for scraping.
Incorrect! Try again.
Did this save you a night before the exam?
LPU Notes is free, and it stays free. Ads cover part of the server bill.
The rest comes out of a student's own pocket: the domain, the storage,
and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason.
to try again.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it.
What it pays for →