Software Development Exam  >  Software Development Tests  >  Basics of Python  >  Test: Patterns - 2 - Software Development MCQ Download as PDF

Test: Patterns - 2 - Software Development MCQ


Test Description

15 Questions MCQ Test Basics of Python - Test: Patterns - 2

Test: Patterns - 2 for Software Development 2024 is part of Basics of Python preparation. The Test: Patterns - 2 questions and answers have been prepared according to the Software Development exam syllabus.The Test: Patterns - 2 MCQs are made for Software Development 2024 Exam. Find important definitions, questions, notes, meanings, examples, exercises, MCQs and online tests for Test: Patterns - 2 below.
Solutions of Test: Patterns - 2 questions in English are available as part of our Basics of Python for Software Development & Test: Patterns - 2 solutions in Hindi for Basics of Python course. Download more important topics, notes, lectures and mock test series for Software Development Exam by signing up for free. Attempt Test: Patterns - 2 | 15 questions in 30 minutes | Mock test for Software Development preparation | Free important questions MCQ to study Basics of Python for Software Development Exam | Download free PDF with solutions
1 Crore+ students have signed up on EduRev. Have you? Download the App
Test: Patterns - 2 - Question 1

Which statement best describes patterns in Python?

Detailed Solution for Test: Patterns - 2 - Question 1

Patterns in Python refer to regular expressions that allow us to match and manipulate specific patterns of text or data.

Test: Patterns - 2 - Question 2

What is the purpose of regular expressions in Python?

Detailed Solution for Test: Patterns - 2 - Question 2

Regular expressions in Python are primarily used to search for and match specific patterns within strings.

Test: Patterns - 2 - Question 3

Which module in Python is used for regular expression operations?

Detailed Solution for Test: Patterns - 2 - Question 3

The "re" module in Python provides support for regular expression operations.

Test: Patterns - 2 - Question 4

Which character is used to represent any single character in a regular expression pattern?

Detailed Solution for Test: Patterns - 2 - Question 4

The dot character (".") in a regular expression pattern represents any single character.

Test: Patterns - 2 - Question 5

What does the "^" character represent in a regular expression pattern?

Detailed Solution for Test: Patterns - 2 - Question 5

The "^" character in a regular expression pattern is used to match the beginning of a line.

Test: Patterns - 2 - Question 6

What will be the output of the following code?
import re

pattern = r"co[a-z]+e"
text = "I love coding and coffee!"
result = re.findall(pattern, text)
print(result)
 

Detailed Solution for Test: Patterns - 2 - Question 6

The regular expression pattern "co[a-z]+e" will match any substring starting with "co", followed by one or more lowercase letters, and ending with "e".

Test: Patterns - 2 - Question 7

What will be the output of the following code?
import re

pattern = r"\b\d{3}-\d{3}-\d{4}\b"
text = "Contact me at 123-456-7890"
result = re.search(pattern, text)
print(result.group())

Detailed Solution for Test: Patterns - 2 - Question 7

The regular expression pattern "\b\d{3}-\d{3}-\d{4}\b" will match a phone number in the format "XXX-XXX-XXXX". The search() function returns the first occurrence that matches the pattern.

Test: Patterns - 2 - Question 8

What will be the output of the following code?
import re

pattern = r"\b[A-Z][a-z]+\b"
text = "The quick Brown fox jumps over the lazy Dog"
result = re.findall(pattern, text)
print(result)

Detailed Solution for Test: Patterns - 2 - Question 8

The regular expression pattern "\b[A-Z][a-z]+\b" will match words starting with an uppercase letter followed by one or more lowercase letters. The findall() function returns all matches in the text.

Test: Patterns - 2 - Question 9

What will be the output of the following code?
import re

pattern = r"\b([a-z]+) \1\b"
text = "The cat in the hat is the best cat"
result = re.findall(pattern, text)
print(result)
 

Detailed Solution for Test: Patterns - 2 - Question 9

The regular expression pattern "\b([a-z]+) \1\b" uses a capturing group to match a word followed by a space and the same word again. The findall() function returns all matches in the text.

Test: Patterns - 2 - Question 10

What will be the output of the following code?
import re

pattern = r"\d+"
text = "There are 10 apples and 20 oranges."
result = re.split(pattern, text)
print(result)

Detailed Solution for Test: Patterns - 2 - Question 10

The split() function splits the text based on the regular expression pattern "\d+", which matches one or more digits. The resulting list contains the substrings between the digits.

Test: Patterns - 2 - Question 11

Which pattern can be used to match an email address format?

Detailed Solution for Test: Patterns - 2 - Question 11

The pattern "r"\w+@\w+.\w+"" matches an email address in the format "username@domain.extension" where "username", "domain", and "extension" consist of one or more word characters.

Test: Patterns - 2 - Question 12

Given the following code, what will be the output?
import re

pattern = r"\b[A-Za-z]+\b"
text = "The quick brown fox jumps over the lazy dog."
result = re.findall(pattern, text)
print(len(result))
 

Detailed Solution for Test: Patterns - 2 - Question 12

The regular expression pattern "\b[A-Za-z]+\b" matches words in the given text. The findall() function returns a list of all matched words, and len(result) gives the count of matched words.

Test: Patterns - 2 - Question 13

Which regular expression pattern can be used to match a URL starting with "https://"?

Detailed Solution for Test: Patterns - 2 - Question 13

The pattern "r"^https://\w+.\w+.\w+$"" matches a URL starting with "https://" followed by a domain and extension. The caret (^) matches the start of the string, and the dollar sign ($) matches the end of the string.

Test: Patterns - 2 - Question 14

What will be the output of the following code?
import re

pattern = r"\d{2}-\d{2}-\d{4}"
text = "DOB: 01-01-2000, SSN: 123-45-6789"
result = re.findall(pattern, text)
print(result)
 

Detailed Solution for Test: Patterns - 2 - Question 14

The regular expression pattern "\d{2}-\d{2}-\d{4}" matches two digits, followed by a hyphen, followed by two digits, another hyphen, and four digits. The findall() function returns a list of all matched patterns in the text.

Test: Patterns - 2 - Question 15

What will be the output of the following code?
import re

pattern = r"\b[A-Z][a-z]+\b"
text = "The quick brown fox jumps over the lazy dog."
result = re.sub(pattern, "animal", text)
print(result)

Detailed Solution for Test: Patterns - 2 - Question 15

The sub() function replaces all matches of the pattern "\b[A-Z][a-z]+\b" with the string "animal".

49 videos|38 docs|18 tests
Information about Test: Patterns - 2 Page
In this test you can find the Exam questions for Test: Patterns - 2 solved & explained in the simplest way possible. Besides giving Questions and answers for Test: Patterns - 2, EduRev gives you an ample number of Online tests for practice
49 videos|38 docs|18 tests
Download as PDF
Download the FREE EduRev App
Track your progress, build streaks, highlight & save important lessons and more!