Python for Data Science
- 48Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
What is the primary focus of the course described in the transcript?
What is the primary focus of the course described in the transcript?
48 questions
- 1
What is the primary focus of the course described in the transcript?
- A
Mastering Python for system administration
- B
Mastering Python for web development
- C
Mastering Python for advanced machine learning
- D
Mastering Python for beginners in data science
Correct answer
DMastering Python for beginners in data science
Explanation
The course is titled 'mastering Python for beginners in data science' and explicitly states its focus on teaching Python for data science.
- A
- 2
According to the transcript, why is Python particularly important for data science?
- A
It is the only language that can handle large datasets
- B
It provides a vast variety of applications and packages for data science
- C
It is the fastest programming language
- D
It is the most secure programming language
Correct answer
BIt provides a vast variety of applications and packages for data science
Explanation
The transcript states that Python provides a vast variety of applications used in data science and offers flexibility in machine learning and deep learning.
- A
- 3
What is an algorithm according to the transcript?
- A
A complete Python program
- B
A flowchart drawn on paper
- C
A set of rules for coding
- D
A step-by-step solution to a problem
Correct answer
DA step-by-step solution to a problem
Explanation
The transcript defines an algorithm as a step-by-step procedure or general solution that works for every instance of a problem.
- A
- 4
In the problem-solving example of finding the customer with maximum sales, what is the tie-breaking rule?
- A
Pick the first record from top to bottom among those with maximum sales
- B
Pick the record with the most recent entry
- C
Pick the record with the highest sales value
- D
Pick a random record among those with maximum sales
Correct answer
APick the first record from top to bottom among those with maximum sales
Explanation
The transcript states: 'if there are more than one records with maximum sales, then pick the first one from top to bottom and ignore the rest'.
- A
- 5
What is the purpose of a pseudocode according to the transcript?
- A
To express algorithms in an unambiguous, concise way using structured keywords
- B
To directly execute code on a computer
- C
To draw graphical representations of algorithms
- D
To replace all programming languages
Correct answer
ATo express algorithms in an unambiguous, concise way using structured keywords
Explanation
Pseudocode is described as a structured way to express algorithms with unambiguous statements, using keywords like input, while, if, etc., without natural language ambiguity.
- A
- 6
In the transcript, what is the main advantage of pseudocode over flowcharts when the goal is to convert to actual programming code?
- A
Flowcharts cannot represent loops
- B
Flowcharts are more precise
- C
Pseudocode is graphical and intuitive
- D
Pseudocode is easier to convert to code
Correct answer
DPseudocode is easier to convert to code
Explanation
The transcript states that writing pseudocode is more feasible because converting pseudocode to code is simpler than converting flowcharts to code.
- A
- 7
In the selection sort algorithm described in the transcript, what is the first step in each iteration?
- A
Find the maximum value and swap it with the last element
- B
Divide the list into halves and recursively sort them
- C
Compare adjacent elements and swap them if needed
- D
Find the minimum value and swap it with the first element of the remaining list
Correct answer
DFind the minimum value and swap it with the first element of the remaining list
Explanation
The selection sort algorithm finds the minimum value in the list (or remaining portion) and swaps it with the first element of that portion.
- A
- 8
Which tool is recommended in the transcript for installing Python with pre-installed packages like Jupyter Notebook?
- A
Python.org installer
- B
Miniconda
- C
pip package manager
- D
Anaconda distribution
Correct answer
DAnaconda distribution
Explanation
The transcript recommends using Anaconda distribution because it includes Python, many packages pre-installed, and Jupyter Notebook.
- A
- 9
In Python, what is the default index of the first element in a list?
- A
1
- B
It depends on the list type
- C
0
- D
-1
Correct answer
C0
Explanation
The transcript explicitly states that in Python, indexing starts from 0, not 1.
- A
- 10
What is the output of the following Python code?
x = 5; print(x + 3.2)- A
5 + 3.2
- B
8
- C
Error: type mismatch
- D
8.2
Correct answer
D8.2
Explanation
Python automatically upcasts integer to float when adding an int and float, resulting in 8.2.
- A
- 11
Which of the following is a valid variable name in Python?
- A
class
- B
my-var
- C
_var
- D
3x
Correct answer
C_var
Explanation
Variable names can start with an underscore. They cannot start with a digit, contain hyphens, or be reserved keywords like 'class'.
- A
- 12
What does the
booldata type in Python represent?- A
Floating point numbers
- B
Any integer value
- C
Complex numbers
- D
True or False values
Correct answer
DTrue or False values
Explanation
The bool data type has only two values: True and False.
- A
- 13
What is the result of
True and Falsein Python?- A
None
- B
True
- C
False
- D
Error
Correct answer
CFalse
Explanation
The 'and' operator returns True only if both operands are True. Since False is one operand, the result is False.
- A
- 14
What does the
==operator do in Python?- A
Checks if two variables refer to the same object
- B
Assigns a value to a variable
- C
Returns True if both values are identical in type and value
- D
Compares two values for equality
Correct answer
DCompares two values for equality
Explanation
The == operator is used for comparison, not assignment. It returns a Boolean value indicating whether the two operands are equal.
- A
- 15
In Python, what is the purpose of the
ifstatement?- A
To conditionally execute a block of code based on a Boolean expression
- B
To repeat a block of code multiple times
- C
To define a function
- D
To import external modules
Correct answer
ATo conditionally execute a block of code based on a Boolean expression
Explanation
The if statement evaluates a condition and executes the indented block only if the condition is True.
- A
- 16
What is the difference between
elifandelsein an if-elif-else structure?- A
elif is used only once; else can be used multiple times
- B
elif is used for additional conditions; else is a catch-all for when no condition is True
- C
There is no difference; they are interchangeable
- D
elif requires a condition; else does not require a colon
Correct answer
Belif is used for additional conditions; else is a catch-all for when no condition is True
Explanation
elif allows checking multiple conditions; else executes if none of the previous conditions are True.
- A
- 17
What does the
breakstatement do inside a loop?- A
Exits the entire program
- B
Skips the rest of the current iteration and starts the next iteration
- C
Terminates the loop immediately and continues with the next statement after the loop
- D
Pauses the loop until a condition is met
Correct answer
CTerminates the loop immediately and continues with the next statement after the loop
Explanation
The break statement exits the loop immediately, regardless of the loop condition.
- A
- 18
What is the output of the following code?
for i in range(3): print(i)- A
1 2 3
- B
0 1 2 3
- C
0 1 2
- D
0 1
Correct answer
C0 1 2
Explanation
range(3) generates numbers 0, 1, 2. The loop prints each on a new line.
- A
- 19
In Python, what does the
elseclause in aforloop do?- A
It executes when the loop condition becomes False
- B
It executes after each iteration
- C
It executes when the loop completes all iterations without a break
- D
It executes only if the loop body is empty
Correct answer
CIt executes when the loop completes all iterations without a break
Explanation
The else clause in a for loop runs only if the loop finishes normally (i.e., not interrupted by a break).
- A
- 20
What is the purpose of the
defkeyword in Python?- A
To declare a variable
- B
To define a class
- C
To define a function
- D
To delete a variable
Correct answer
CTo define a function
Explanation
The def keyword is used to define (create) a function.
- A
- 21
What is a docstring in a function?
- A
A string used to define default arguments
- B
A string used to document what the function does, accessible via help()
- C
A special comment that is ignored by Python
- D
A string that is automatically printed when the function is called
Correct answer
BA string used to document what the function does, accessible via help()
Explanation
A docstring is a string literal placed as the first statement in a function body, used to describe the function's purpose, and can be viewed using help().
- A
- 22
How does Python handle a variable number of arguments in a function?
- A
Both of the above
- B
By using the
*argsparameter to capture positional arguments as a tuple - C
By using the
**kwargsparameter to capture keyword arguments as a dictionary - D
Python does not support variable number of arguments
Correct answer
ABoth of the above
Explanation
Python allows
*argsfor variable positional arguments and**kwargsfor variable keyword arguments. - A
- 23
What is the scope of a variable defined inside a function?
- A
Built-in: accessible in all Python code
- B
Enclosing: accessible in nested functions
- C
Global: accessible everywhere
- D
Local: accessible only inside the function
Correct answer
DLocal: accessible only inside the function
Explanation
Variables defined inside a function are local to that function and cannot be accessed outside it unless returned.
- A
- 24
What is a Python module?
- A
A built-in data structure
- B
A file containing Python code that can be imported into other programs
- C
A single function used in a program
- D
A type of variable
Correct answer
BA file containing Python code that can be imported into other programs
Explanation
A module is a .py file containing functions, variables, and classes that can be reused by importing into other Python scripts.
- A
- 25
How do you import a custom module named
mymod.pylocated in a different directory?- A
Copy the module into the Python library directory
- B
Use
import mymodand specify the full path in the import statement - C
Add the directory to
sys.pathand then useimport mymod - D
Just write
import mymodand Python will find it automatically
Correct answer
CAdd the directory to
sys.pathand then useimport mymodExplanation
To import a module from a non-standard location, you must add its path to sys.path using sys.path.append(path) before importing.
- A
- 26
In Python, what is the result of
'Hello' + ' World'?- A
'HelloWorld'
- B
Error: cannot concatenate strings
- C
'Hello World '
- D
'Hello World'
Correct answer
D'Hello World'
Explanation
The + operator concatenates strings, resulting in 'Hello World' (including the space).
- A
- 27
What does the string method
strip()do?- A
Removes all spaces from the string
- B
Removes leading and trailing whitespace
- C
Removes all occurrences of a specified substring
- D
Converts the string to lowercase
Correct answer
BRemoves leading and trailing whitespace
Explanation
The strip() method removes whitespace from both ends of the string.
- A
- 28
How can you access the last character of a string
sin Python?- A
s[-1]
- B
s[len(s)]
- C
s.last
- D
s[0]
Correct answer
As[-1]
Explanation
Negative indexing starts from the end; -1 refers to the last character.
- A
- 29
What will
s = 'abcdef'; print(s[1:4])output?- A
'bcd'
- B
'abc'
- C
'abcd'
- D
'bcde'
Correct answer
A'bcd'
Explanation
Slicing s[start:stop] returns characters from index start (inclusive) to stop (exclusive). Here, indices 1,2,3 are 'b','c','d'.
- A
- 30
Which of the following correctly splits the string
'a,b,c'into a list?- A
'a,b,c'.split()
- B
'a,b,c'.partition(',')
- C
split('a,b,c', ',')
- D
'a,b,c'.split(',')
Correct answer
D'a,b,c'.split(',')
Explanation
The split() method with a separator splits the string into a list of substrings.
- A
- 31
What is the difference between a list and a tuple in Python?
- A
Lists are mutable; tuples are immutable
- B
Lists can only contain numbers; tuples can contain any type
- C
Lists are immutable; tuples are mutable
- D
There is no difference
Correct answer
ALists are mutable; tuples are immutable
Explanation
Lists are mutable (can be changed), while tuples are immutable (cannot be changed after creation).
- A
- 32
Which data structure in Python does not allow duplicate elements?
- A
Dictionary
- B
List
- C
Set
- D
Tuple
Correct answer
CSet
Explanation
A set is an unordered collection of unique elements; duplicates are automatically removed.
- A
- 33
How do you add a single element to an existing set
s?- A
s.push(element)
- B
s.insert(element)
- C
s.append(element)
- D
s.add(element)
Correct answer
Ds.add(element)
Explanation
The add() method is used to add a single element to a set.
- A
- 34
In a dictionary, what must each key be?
- A
Unique only within the dictionary values
- B
Mutable
- C
Immutable and hashable
- D
A string
Correct answer
CImmutable and hashable
Explanation
Dictionary keys must be immutable and hashable (e.g., strings, numbers, tuples).
- A
- 35
What happens when you assign one list to another variable in Python (e.g.,
a = [1,2]; b = a)?- A
b becomes a reference to the same list object, so changes through b affect a
- B
a and b are independent copies
- C
An error occurs
- D
a list is copied automatically
Correct answer
Ab becomes a reference to the same list object, so changes through b affect a
Explanation
Assignment of a mutable object creates a reference, not a copy. Both names refer to the same list in memory.
- A
- 36
What is the purpose of
np.arange(10)in NumPy?- A
Creates a list of numbers from 0 to 9
- B
Creates a range object similar to Python's range
- C
Creates a NumPy array of numbers from 0 to 9
- D
Creates a random permutation of numbers from 0 to 10
Correct answer
CCreates a NumPy array of numbers from 0 to 9
Explanation
np.arange returns a NumPy array with evenly spaced values within the given range. For example, np.arange(10) gives array([0,1,...,9]).
- A
- 37
What does the
shapeattribute of a NumPy array return?- A
The number of dimensions
- B
A tuple representing the size of each dimension
- C
The total number of elements
- D
The data type of the array
Correct answer
BA tuple representing the size of each dimension
Explanation
The shape attribute returns a tuple with the length of each dimension of the array.
- A
- 38
In NumPy, what is the difference between slicing with
:and using an integer index?- A
Both return copies
- B
Both return views
- C
Slicing returns a view (reference) while integer indexing returns a copy
- D
Slicing returns a copy while integer indexing returns a view
Correct answer
CSlicing returns a view (reference) while integer indexing returns a copy
Explanation
In NumPy, slicing returns a view of the original array (no data copied), whereas integer indexing (like fancy indexing) returns a copy.
- A
- 39
How can you create a 3x4 matrix of random numbers uniformly distributed between 0 and 1 using NumPy?
- A
np.random.randn(3,4)
- B
np.random.rand(3,4)
- C
np.random.randint(0,1, (3,4))
- D
np.random.uniform(0,1, (3,4))
Correct answer
Bnp.random.rand(3,4)
Explanation
np.random.rand(3,4) creates an array of shape (3,4) with random floats in [0,1).
- A
- 40
What does the
axisparameter in NumPy functions likenp.sum()indicate?- A
The number of dimensions to sum over
- B
The number of times to repeat the operation
- C
The data type of the result
- D
The axis along which the operation is performed (0 for column-wise, 1 for row-wise)
Correct answer
DThe axis along which the operation is performed (0 for column-wise, 1 for row-wise)
Explanation
The axis parameter specifies the dimension along which to compute the operation. For a 2D array, axis=0 sums over rows (column-wise), axis=1 sums over columns (row-wise).
- A
- 41
In pandas, what is the primary difference between a Series and a DataFrame?
- A
Series is one-dimensional; DataFrame is two-dimensional
- B
There is no difference
- C
Series can only contain numbers; DataFrame can contain any data type
- D
Series is mutable; DataFrame is immutable
Correct answer
ASeries is one-dimensional; DataFrame is two-dimensional
Explanation
A Series is a one-dimensional labeled array, while a DataFrame is a two-dimensional labeled data structure with columns.
- A
- 42
How do you read a CSV file into a pandas DataFrame?
- A
pd.open_csv(filename)
- B
pd.read_csv(filename)
- C
pd.load_csv(filename)
- D
pd.import_csv(filename)
Correct answer
Bpd.read_csv(filename)
Explanation
The function to read a CSV file is pd.read_csv().
- A
- 43
What does the
head()method in pandas do?- A
Returns a summary of the DataFrame
- B
Returns the column names
- C
Returns the first few rows (default 5) of the DataFrame
- D
Returns the last few rows of the DataFrame
Correct answer
CReturns the first few rows (default 5) of the DataFrame
Explanation
The head() method returns the first n rows (default 5) of the DataFrame.
- A
- 44
How can you handle missing values (NaN) in a pandas DataFrame by filling them with a constant?
- A
df.dropna()
- B
df.replace(NaN, value)
- C
df.impute(value)
- D
df.fillna(value)
Correct answer
Ddf.fillna(value)
Explanation
The fillna() method fills missing values with a specified value.
- A
- 45
In pandas, what is the difference between
ilocandlocfor indexing?- A
Both use integer positions
- B
iloc uses labels; loc uses integer positions
- C
iloc uses integer positions; loc uses labels
- D
Both use labels
Correct answer
Ciloc uses integer positions; loc uses labels
Explanation
iloc is integer-location based indexing (like standard NumPy), while loc is label-based indexing.
- A
- 46
What does the
groupby()method in pandas do?- A
Groups rows by a column and then applies an aggregate function
- B
Sorts the DataFrame by a column
- C
Removes duplicate rows
- D
Creates a new column based on a condition
Correct answer
AGroups rows by a column and then applies an aggregate function
Explanation
groupby() splits the data into groups based on a column, allowing you to apply aggregation functions like sum, mean, etc.
- A
- 47
Which function in matplotlib is used to create a line plot?
- A
plt.lineplot()
- B
plt.plot()
- C
plt.hist()
- D
plt.scatter()
Correct answer
Bplt.plot()
Explanation
The plot() function is used for line plots.
- A
- 48
How can you display a plot created with matplotlib in a Jupyter Notebook?
- A
plt.display()
- B
plt.print()
- C
plt.render()
- D
plt.show()
Correct answer
Dplt.show()
Explanation
The plt.show() command displays the figure in the notebook.
- A

Ask anything
We've read this whole study set, so questions about it get the best answers.