0% found this document useful (0 votes)
18 views

Python For Data Science PART 3

The document contains a series of important questions and answers related to Python programming, specifically focusing on data science applications. Key topics include string manipulation, data structures, exception handling, file operations, and functional programming concepts. Each question is followed by the accepted answer, providing a concise reference for learners.

Uploaded by

sboy76385
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Python For Data Science PART 3

The document contains a series of important questions and answers related to Python programming, specifically focusing on data science applications. Key topics include string manipulation, data structures, exception handling, file operations, and functional programming concepts. Each question is followed by the accepted answer, providing a concise reference for learners.

Uploaded by

sboy76385
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Python for Data Science IIT Kharagpur

Python For Data Science

IMP QUESTIONS PART 3

Question 18:
What is the purpose of the 'split()' method for strings in Python?
A) Joins two strings together
B) Removes whitespace characters from the string

AM
C) Splits the string into a list of substrings based on a specified delimiter
D) Converts the string to lowercase

Accepted Answer: C) Splits the string into a list of substrings based on a


specified delimiter

Question 19:
AY
SW
Which data structure in Python is used to store key-value pairs?
A) List
B) Tuple
C) Set
D) Dictionary
Y

Accepted Answer: D) Dictionary


M

Question 20:
@

What is the purpose of the try' and 'except' blocks in Python?

A) To define a loop
B) To create a function
C) To handle exceptions and errors in code
D) To import external libraries

Accepted Answer: C) To handle exceptions and errors in code

Page 1 MY SWAYAM
Python for Data Science IIT Kharagpur

Question 21:
What is the correct way to open a file in Python?
A) open(file_name, "r")
B) read(file_name, "open")
C) file.open(file_name)
D) file(file_name)

Accepted Answer: A) open(file_name, "r")

AM
Question 22:
What does the 'with' statement do when working with files in Python?

AY
A) It opens the file in write mode
B) It ensures proper acquisition and release of resources, like file handling,
during file operations
C) It converts the file to uppercase
SW
D) It reads the file content

Accepted Answer: B) It ensures proper acquisition and release of resources,


like file handling, during file operations
Y

Question 23:
What is the purpose of list comprehensions in Python?
M

A) To define a list
B) To iterate over a sequence and apply an operation to each element to
@

create a new list


C) To remove elements from a list
D) To sort a list in descending order

Accepted Answer: B) To iterate over a sequence and apply an operation to


each element to create a new list

Page 2 MY SWAYAM
Python for Data Science IIT Kharagpur

Question 24:
Which statement is used to exit a loop prematurely in Python?
A) stop
B) exit
C) break
D) end

Accepted Answer: C) break

AM
Question 25:
What is the purpose of the 'map()' function in Python?
A) To create a dictionary

C) To sort a list
D) To concatenate strings
AY
B) To apply a function to all items in an input list and return an iterator
SW
Accepted Answer: B) To apply a function to all items in an input list and return
an iterator

Question 26:
Which keyword is used to define a function in Python that can accept a
Y

variable number of arguments?


A) flex
M

B) varargs
C) args
@

D) *args

Accepted Answer: D) *args

Page 3 MY SWAYAM
Python for Data Science IIT Kharagpur

Question 27:
What does the 'lambda' keyword represent in Python?
A) A keyword to declare a variable
B) A keyword to declare a constant
C) A keyword to define an anonymous function (a function with no name)
D) A keyword to define a class

Accepted Answer: C) A keyword to define an anonymous function (a function


with no name)

AM
Question 28:
What is the purpose of the 'filter()' function in Python?
A) To filter elements from a list based on a specified condition

AY
B) To filter out numbers from a string
C) To filter elements from a list based on their index
D) To filter characters from a string
SW

Accepted Answer: A) To filter elements from a list based on a specified


condition

Question 29:
Y

What does the 'reduce()' function do in Python?


A) Combines all elements of a list into a single string
M

B) Applies a function of two arguments cumulatively to the items of iterable,


from left to right, so as to reduce the iterable to a single value
@

C) Reverses the elements of a list


D) Splits a string into a list of substrings

Accepted Answer: B) Applies a function of two arguments cumulatively to the


items of iterable, from left to right, so as to reduce the iterable to a single
value

Page 4 MY SWAYAM
Python for Data Science IIT Kharagpur

Question 30:
What is the purpose of the 'zip()' function in Python?
A) To compress files
B) To combine two or more lists element-wise into a list of tuples
C) To unzip files
D) To zip large data files

Accepted Answer: B) To combine two or more lists element-wise into a list of


tuples

AM
Question 31:
What is the purpose of the 'enumerate()' function in Python?
A) To create a numbered list

AY
B) To iterate over a sequence and keep track of the index of the current item
C) To count the number of elements in a sequence
D) To remove duplicates from a list
SW

Accepted Answer: B) To iterate over a sequence and keep track of the index
of the current item

Question 32:
Y

What does the 'any()' function do in Python?


A) Returns True if all elements of an iterable are true
M

B) Returns True if any element of an iterable is true


C) Returns True if all elements of an iterable are false
@

D) Returns True if any element of an iterable is false

Accepted Answer: B) Returns True if any element of an iterable is true

Page 5 MY SWAYAM
Python for Data Science IIT Kharagpur

Subscribe for

PART 4

MY SWAYAM

PDF OF ALL ABOVE QUESTIONS IS AVAILABLE IN THE

AM
DESCRIPTION BOX OF THIS VIDEO.

WANT TO NEXT PART , COMMENT BELOW AND SUBSCRIBE


THIS YOUTUBE CHANNEL “MY SWAYAM”

HAPPY LEARNING
THANK YOU.
AY
SW
Y
M
@

Page 6 MY SWAYAM

You might also like