100 MCQs on Python, NumPy, and Pandas for
Amex Online Assessments
These multiple-choice questions (MCQs) are designed to cover fundamental and practical
aspects of Python, NumPy, and Pandas, drawing relevance from American Express online
assessment tests. Based on insights from Amex coding assessments, which often include
Python-based problem-solving, data manipulation, and algorithmic challenges [1] [2] [3] , the
questions emphasize coding efficiency, data handling, and logical reasoning. Each MCQ includes
four options, the correct answer, and a brief explanation.
The questions are divided into three sections:
General Python (Questions 1-40): Focus on core language features, data structures, and
functions commonly tested in coding rounds.
NumPy (Questions 41-70): Cover array operations, broadcasting, and numerical
computations, relevant for data-intensive tasks.
Pandas (Questions 71-100): Address dataframes, series, and data analysis, aligning with
analytical roles.
Section 1: General Python (Questions 1-40)
Question 1: What is the output of print(type([])) in Python?
A) <class 'tuple'>
B) <class 'list'>
C) <class 'dict'>
D) <class 'set'>
Answer: B
Explanation: The type() function returns the class type of an empty list, which is a mutable
sequence [4] .
Question 2: Which keyword is used to define a function in Python?
A) func
B) def
C) function
D) lambda
Answer: B
Explanation: The def keyword is used to declare user-defined functions, a basic concept in
Python coding problems [4] .
Question 3: What does the len() function return for a string "Amex"?
A) 4
B) 5
C) 3
D) Error
Answer: A
Explanation: len() counts the number of characters in the string, useful for string manipulation
in assessments [1] .
Question 4: How do you create a list comprehension to square numbers from 1 to 5?
A) [x**2 for x in range(1,6)]
B) {x**2 for x in range(1,6)}
C) (x**2 for x in range(1,6))
D) [x*2 for x in range(1,6)]
Answer: A
Explanation: List comprehensions are efficient for generating lists, often tested in Python
efficiency questions [4] .
Question 5: What is the result of 2 + 3 * 4 in Python?
A) 20
B) 14
C) 15
D) 24
Answer: B
Explanation: Operator precedence multiplies before adding, a fundamental arithmetic rule [4] .
Question 6: Which data structure is unordered and does not allow duplicates?
A) List
B) Tuple
C) Set
D) Dictionary
Answer: C
Explanation: Sets are ideal for unique elements, relevant in deduplication tasks [1] .
Question 7: How do you access the value of key 'a' in dict d = {'a':1}?
A) d.a
B) d['a']
C) d( a )
D) d.get(a)
Answer: B
Explanation: Bracket notation accesses dictionary values, common in data mapping
problems [4] .
Question 8: What does range(5) generate?
A) [1] [5] [2] [3]
B) [1] [5] [2] [3] [4]
C) (0,1,2,3,4)
D) Error
Answer: A
Explanation: range() starts from 0 by default, used in loops for iterations [4] .
Question 9: Which loop is used to iterate over a sequence?
A) while
B) for
C) do-while
D) repeat
Answer: B
Explanation: for loops are efficient for sequences, tested in algorithmic challenges [1] .
Question 10: What is the output of print("Hello"[-1])?
A) H
B) o
C) e
D) Error
Answer: B
Explanation: Negative indexing accesses the last character, useful in string reversals [4] .
Question 11: How do you handle exceptions in Python?
A) try-except
B) catch-error
C) error-try
D) except-try
Answer: A
Explanation: try-except blocks manage errors, important for robust code in tests [2] .
Question 12: What is a lambda function?
A) Named function
B) Anonymous function
C) Class method
D) Generator
Answer: B
Explanation: Lambdas are inline functions, often used in functional programming questions [3] .
Question 13: Which module is used for mathematical operations?
A) math
B) random
C) os
D) sys
Answer: A
Explanation: The math module provides functions like sqrt, relevant for computations [4] .
Question 14: What does list.append(1) do?
A) Adds 1 to the end
B) Adds 1 to the start
C) Removes 1
D) Sorts the list
Answer: A
Explanation: append() modifies lists in place, common in dynamic data handling [1] .
Question 15: How do you check if a key exists in a dictionary?
A) key in dict
B) dict.has(key)
C) dict.exists(key)
D) key exists dict
Answer: A
Explanation: The in operator is efficient for membership testing [4] .
Question 16: What is the output of bool(0)?
A) True
B) False
C) 0
D) Error
Answer: B
Explanation: Zero is falsy in Python, used in conditional logic [4] .
Question 17: Which is immutable?
A) List
B) Set
C) Tuple
D) Dictionary
Answer: C
Explanation: Tuples cannot be changed, useful for constant data [4] .
Question 18: What does sorted([^2][^1][^5]) return?
A) [1] [5] [2]
B) [2] [1] [5]
C) [5] [1] [2]
D) Error
Answer: A
Explanation: sorted() returns a new sorted list, tested in sorting problems [1] .
Question 19: How do you open a file for reading?
A) open('file', 'r')
B) open('file', 'w')
C) open('file', 'a')
D) open('file')
Answer: A
Explanation: 'r' mode is for reading, relevant in file I/O questions [4] .
Question 20: What is the purpose of __init__ in a class?
A) Destructor
B) Constructor
C) Method
D) Variable
Answer: B
Explanation: It's the initializer for objects, key in OOP questions [2] .
Question 21: What does zip([^1][^5], ['a','b']) produce?
A) [(1,'a'), (2,'b')]
B) [1,'a',2,'b']
C) {'1':'a', '2':'b'}
D) Error
Answer: A
Explanation: zip() pairs iterables, useful in data pairing [4] .
Question 22: How do you reverse a list?
A) list.reverse()
B) list.sort(reverse=True)
C) list[::-1]
D) Both A and C
Answer: D
Explanation: Both methods work; slicing is non-mutating [4] .
Question 23: What is the output of print(1 == '1')?
A) True
B) False
C) Error
D) None
Answer: B
Explanation: Types differ, so equality is False; tests type awareness [4] .
Question 24: Which is used for inheritance?
A) class Child(Parent)
B) class Parent(Child)
C) inherit Parent
D) extends Parent
Answer: A
Explanation: Python uses parentheses for inheritance in classes [2] .
Question 25: What does enumerate(['a','b']) yield?
A) [(0,'a'), (1,'b')]
B) ['0a', '1b']
C) [1]
D) Error
Answer: A
Explanation: Adds indices to iterables, common in loop indexing [4] .
Question 26: How do you import a module?
A) import module
B) from module import *
C) Both A and B
D) require module
Answer: C
Explanation: Both ways work; tested in modular code [4] .
Question 27: What is a generator?
A) Function yielding values
B) List creator
C) Dictionary builder
D) Set maker
Answer: A
Explanation: Uses yield for memory efficiency [4] .
Question 28: What does any([True, False]) return?
A) True
B) False
C) Error
D) None
Answer: A
Explanation: Returns True if any element is true [4] .
Question 29: How do you format strings?
A) f"string {var}"
B) "string % var"
C) Both A and B
D) "string".format(var)
Answer: C
Explanation: Multiple ways; f-strings are modern [4] .
Question 30: What is the output of set([^1][^1][^5])?
A) {1,2}
B) [1] [5]
C) (1,2)
D) {1,1,2}
Answer: A
Explanation: Sets remove duplicates automatically [1] .
Question 31: Which is a mutable sequence?
A) String
B) Tuple
C) List
D) Set
Answer: C
Explanation: Lists can be modified, unlike tuples [4] .
Question 32: What does abs(-5) return?
A) 5
B) -5
C) 0
D) Error
Answer: A
Explanation: Absolute value function, basic math [4] .
Question 33: How do you check type equality?
A) isinstance(obj, type)
B) type(obj) == type
C) Both A and B
D) obj.type == type
Answer: C
Explanation: Both work; isinstance handles inheritance [4] .
Question 34: What is the default return of a function?
A) None
B) 0
C) Error
D) True
Answer: A
Explanation: Functions return None if no return statement [4] .
Question 35: Which operator is for floor division?
A) /
B) //
C) %
D) **
Answer: B
Explanation: // returns integer division [4] .
Question 36: What does map(lambda x: x*2, [^1][^5]) return?
A) [5] [3]
B) map object
C) (2,4)
D) Error
Answer: B
Explanation: map() returns an iterator; list() converts it [4] .
Question 37: How do you create a class?
A) class MyClass:
B) def MyClass:
C) class MyClass()
D) new MyClass
Answer: A
Explanation: Basic class definition syntax [2] .
Question 38: What is the output of print(ord('A'))?
A) 65
B) A
C) 97
D) Error
Answer: A
Explanation: ord() gives ASCII value [4] .
Question 39: Which is used for comments?
A) #
B) //
C) /* */
D) --
Answer: A
Explanation: Single-line comments use # [4] .
Question 40: What does globals() return?
A) Global variables dict
B) Local variables dict
C) Both
D) Error
Answer: A
Explanation: Accesses global namespace, advanced usage [4] .
Section 2: NumPy (Questions 41-70)
Question 41: What is NumPy primarily used for?
A) Numerical computations
B) Data visualization
C) Web scraping
D) Database management
Answer: A
Explanation: NumPy supports array operations for scientific computing [6] .
Question 42: How do you import NumPy?
A) import numpy as np
B) from numpy import *
C) Both A and B
D) require numpy
Answer: C
Explanation: Standard import methods for array handling [6] .
Question 43: What does np.array([^1][^5][^2]) create?
A) 1D array
B) 2D array
C) List
D) Tuple
Answer: A
Explanation: Creates a NumPy ndarray, faster than lists [6] .
Question 44: What is the shape of np.array([[^1][^5],[^2][^3]])?
A) (2,2)
B) (4,)
C) (1,4)
D) Error
Answer: A
Explanation: shape attribute gives dimensions [6] .
Question 45: How do you create an array of zeros?
A) np.zeros(5)
B) np.empty(5)
C) np.ones(5) * 0
D) Both A and C
Answer: D
Explanation: np.zeros() is direct; useful for initialization [6] .
Question 46: What does broadcasting allow in NumPy?
A) Operations on different shapes
B) Array copying
C) Data sorting
D) File I/O
Answer: A
Explanation: Enables element-wise ops without explicit looping [6] .
Question 47: What is np.arange(0,10,2)?
A) [5] [3] [6] [7]
B) [1] [2] [4] [8] [9]
C) [1] [5] [2] [3]
D) Error
Answer: A
Explanation: Similar to range, but returns array [6] .
Question 48: How do you find the max in an array?
A) np.max(arr)
B) arr.max()
C) Both A and B
D) max(arr)
Answer: C
Explanation: Both work for statistical ops [6] .
Question 49: What does np.linspace(0,1,5) produce?
A) [0., 0.25, 0.5, 0.75, 1.]
B) [1] [5] [2] [3]
C) [0,0.2,0.4,0.6,0.8]
D) Error
Answer: A
Explanation: Evenly spaced values, for sampling [6] .
Question 50: What is the dtype of np.array([^1][^5])?
A) int64
B) float64
C) object
D) str
Answer: A
Explanation: Defaults to integer type [6] .
Question 51: How do you reshape an array to 2x3?
A) arr.reshape(2,3)
B) np.reshape(arr, (2,3))
C) Both A and B
D) arr.shape = (2,3)
Answer: C
Explanation: Reshaping for matrix ops [6] .
Question 52: What does np.dot(a,b) compute?
A) Dot product
B) Element-wise multiply
C) Sum
D) Difference
Answer: A
Explanation: For linear algebra, relevant in data roles [6] .
Question 53: How do you slice the first row of a 2D array?
A) arr[0,:]
B) arr[:,0]
C) arr
D) Both A and C
Answer: D
Explanation: Slicing for subarray access [6] .
Question 54: What is np.random.rand(3)?
A) Array of 3 random floats [0,1)
B) Array of 3 random ints
C) Empty array
D) Error
Answer: A
Explanation: Random number generation for simulations [6] .
Question 55: How do you concatenate two arrays horizontally?
A) np.hstack((a,b))
B) np.vstack((a,b))
C) np.concatenate((a,b), axis=1)
D) Both A and C
Answer: D
Explanation: For merging data [6] .
Question 56: What does np.sum(arr, axis=0) do?
A) Sum along columns
B) Sum along rows
C) Total sum
D) Error
Answer: A
Explanation: Axis parameter for aggregation [6] .
Question 57: How do you find unique elements?
A) np.unique(arr)
B) set(arr)
C) Both A and B
D) arr.unique()
Answer: A
Explanation: Returns sorted unique values [6] .
Question 58: What is the purpose of np.where?
A) Conditional selection
B) Array creation
C) Sorting
D) Reshaping
Answer: A
Explanation: For masking and filtering [6] .
Question 59: How do you compute mean?
A) np.mean(arr)
B) arr.mean()
C) Both A and B
D) sum(arr)/len(arr)
Answer: C
Explanation: Statistical function for analysis [6] .
Question 60: What does arr.T do?
A) Transpose array
B) Reverse array
C) Sort array
D) Flatten array
Answer: A
Explanation: For matrix transposition [6] .
Question 61: How do you create an identity matrix?
A) np.eye(3)
B) np.identity(3)
C) Both A and B
D) np.ones((3,3))
Answer: C
Explanation: For linear algebra ops [6] .
Question 62: What is broadcasting rule?
A) Shapes must match or be 1
B) Arrays must be same size
C) Only for 1D arrays
D) Error if shapes differ
Answer: A
Explanation: Allows flexible operations [6] .
Question 63: How do you flatten an array?
A) arr.flatten()
B) np.ravel(arr)
C) Both A and B
D) arr.reshape(-1)
Answer: C
Explanation: Converts to 1D [6] .
Question 64: What does np.linalg.inv(mat) return?
A) Inverse matrix
B) Determinant
C) Eigenvalues
D) Transpose
Answer: A
Explanation: For solving equations [6] .
Question 65: How do you add a scalar to an array?
A) arr + 5
B) np.add(arr,5)
C) Both A and B
D) loop addition
Answer: C
Explanation: Vectorized operations [6] .
Question 66: What is np.meshgrid used for?
A) Coordinate grids
B) Random grids
C) Sorting
D) Slicing
Answer: A
Explanation: For 2D functions [6] .
Question 67: How do you handle NaN values?
A) np.isnan(arr)
B) np.nanmean(arr)
C) Both A and B
D) arr == np.nan
Answer: C
Explanation: For data cleaning [6] .
Question 68: What does np.vectorize(func) do?
A) Applies func element-wise
B) Creates vector
C) Reshapes
D) Sorts
Answer: A
Explanation: For custom ufuncs [6] .
Question 69: How do you compute standard deviation?
A) np.std(arr)
B) arr.std()
C) Both A and B
D) variance sqrt
Answer: C
Explanation: Statistical measure [6] .
Question 70: What is the difference between copy and view?
A) Copy is independent
B) View shares memory
C) Both A and B
D) No difference
Answer: C
Explanation: Important for memory efficiency [6] .
Section 3: Pandas (Questions 71-100)
Question 71: What is Pandas used for?
A) Data manipulation
B) Numerical arrays
C) Web development
D) Graphics
Answer: A
Explanation: Handles dataframes for analysis, relevant in Amex data roles [3] [10] .
Question 72: How do you import Pandas?
A) import pandas as pd
B) from pandas import *
C) Both A and B
D) require pandas
Answer: C
Explanation: Standard import for data handling [10] .
Question 73: What is a DataFrame?
A) 2D labeled data structure
B) 1D series
C) Dictionary
D) List
Answer: A
Explanation: Like a table, for structured data [10] .
Question 74: How do you create a Series?
A) pd.Series( [1] [5] [2] )
B) pd.DataFrame( [1] [5] [2] )
C) np.array( [1] [5] [2] )
D) list( [1] [5] [2] )
Answer: A
Explanation: Labeled 1D array [10] .
Question 75: What does df.head() show?
A) First 5 rows
B) Last 5 rows
C) All rows
D) Columns
Answer: A
Explanation: For quick data inspection [10] .
Question 76: How do you select a column 'col' from df?
A) df['col']
B) df.col
C) Both A and B
D) df.get('col')
Answer: C
Explanation: Column access methods [10] .
Question 77: What is df.shape?
A) (rows, columns)
B) Data types
C) Index
D) Values
Answer: A
Explanation: Dimensions of dataframe [10] .
Question 78: How do you drop missing values?
A) df.dropna()
B) df.fillna(0)
C) Both A and B
D) df.remove_na()
Answer: A
Explanation: Cleans data, common in preprocessing [10] .
Question 79: What does df.groupby('col').mean() do?
A) Grouped averages
B) Sorts data
C) Merges data
D) Filters data
Answer: A
Explanation: Aggregation by category [10] .
Question 80: How do you merge two dataframes?
A) pd.merge(df1, df2)
B) df1.join(df2)
C) Both A and B
D) df1 + df2
Answer: C
Explanation: For joining datasets [10] .
Question 81: What is df.iloc?
A) First row
B) First column
C) Last row
D) Index 0
Answer: A
Explanation: Integer-based indexing [10] .
Question 82: How do you apply a function to a column?
A) df['col'].apply(func)
B) df.apply(func, axis=1)
C) Both A and B
D) loop over df
Answer: C
Explanation: Vectorized application [10] .
Question 83: What does df.describe() return?
A) Statistical summary
B) Data types
C) Shape
D) Head
Answer: A
Explanation: Mean, std, etc., for overview [10] .
Question 84: How do you sort by a column?
A) df.sort_values('col')
B) df.sort_index()
C) Both A and B
D) sorted(df)
Answer: A
Explanation: Ascending sort by values [10] .
Question 85: What is a Panel in Pandas?
A) 3D data structure
B) 2D dataframe
C) 1D series
D) Deprecated
Answer: D
Explanation: No longer used in recent versions [10] .
Question 86: How do you pivot a dataframe?
A) df.pivot_table()
B) df.pivot()
C) Both A and B
D) df.reshape()
Answer: C
Explanation: For reshaping data [10] .
Question 87: What does df.duplicated() check?
A) Duplicate rows
B) Missing values
C) Data types
D) Unique values
Answer: A
Explanation: For data cleaning [10] .
Question 88: How do you read a CSV file?
A) pd.read_csv('file.csv')
B) pd.load_csv('file.csv')
C) open('file.csv')
D) np.read_csv('file.csv')
Answer: A
Explanation: Imports data into dataframe [10] .
Question 89: What is df.loc['index']?
A) Label-based selection
B) Integer selection
C) Column selection
D) Error
Answer: A
Explanation: Access by labels [10] .
Question 90: How do you fill NaN with mean?
A) df.fillna(df.mean())
B) df.replace(np.nan, df.mean())
C) Both A and B
D) df.dropna()
Answer: A
Explanation: Imputation technique [10] .
Question 91: What does df.corr() compute?
A) Correlation matrix
B) Covariance
C) Sum
D) Mean
Answer: A
Explanation: For feature relationships [10] .
Question 92: How do you rename columns?
A) df.rename(columns={'old':'new'})
B) df.columns = ['new']
C) Both A and B
D) df.set_columns()
Answer: C
Explanation: For data standardization [10] .
Question 93: What is df.value_counts()?
A) Frequency of values
B) Unique values
C) Sum of values
D) Mean of values
Answer: A
Explanation: For categorical analysis [10] .
Question 94: How do you filter rows where 'col' > 5?
A) df[df['col'] > 5]
B) df.query('col > 5')
C) Both A and B
D) loop filter
Answer: C
Explanation: Boolean indexing [10] .
Question 95: What does df.to_csv('file.csv') do?
A) Exports to CSV
B) Reads CSV
C) Deletes file
D) Error
Answer: A
Explanation: Saves dataframe [10] .
Question 96: How do you get unique values in a column?
A) df['col'].unique()
B) df['col'].nunique()
C) A for values, B for count
D) Both A and B
Answer: C
Explanation: For data exploration [10] .
Question 97: What is the purpose of pd.concat?
A) Concatenate dataframes
B) Merge on keys
C) Group data
D) Pivot data
Answer: A
Explanation: Appends along axis [10] .
Question 98: How do you handle datetime?
A) pd.to_datetime(df['date'])
B) df['date'].astype('datetime')
C) Both A and B
D) strptime
Answer: A
Explanation: Converts to datetime type [10] .
Question 99: What does df.sample(5) return?
A) Random 5 rows
B) First 5 rows
C) Last 5 rows
D) All rows
Answer: A
Explanation: For random sampling [10] .
Question 100: How do you compute rolling mean?
A) df.rolling(3).mean()
B) df.mean(rolling=3)
C) loop calculation
D) np.mean(df,3)
Answer: A
Explanation: For time-series analysis [10] .
⁂
1. https://prepinsta.com/american-express-coding-questions-and-answers/
2. https://www.geeksforgeeks.org/interview-experiences/american-express-internship-interview-experie
nce-on-campus/
3. https://www.glassdoor.co.in/Interview/American-Express-Analyst-Data-Science-Interview-Questions-EI_
IE35.0,16_KO17,37.htm
4. https://www.preplaced.in/blog/top-20-python-interv-11
5. https://www.geeksforgeeks.org/interview-experiences/american-express-amex-online-assessment-oa-
interview-experience-experience-interview/
6. https://upesonline.ac.in/blog/frequently-asked-numpy-interview-questions
7. https://www.glassdoor.co.in/Interview/American-Express-Software-Engineer-Interview-Questions-EI_IE
35.0,16_KO17,34.htm
8. https://www.geeksforgeeks.org/american-experess-interview-experience-for-fte-on-campus-2020/
9. https://www.kaggle.com/general/306223
10. https://www.interviewbit.com/pandas-interview-questions/