Python Programming for AI and Data Science
What this domain tests
Python Programming for AI and Data Science tests core syntax plus the three libraries named in the syllabus: NumPy for arrays, pandas for tabular data, and Matplotlib for plots. Questions often combine data types, control flow and a short library operation.
Core rules and concepts
- Data types: int, float, str, bool; collections list, tuple, dict, set. Lists and dicts are mutable; strings and tuples are immutable.
- Control flow uses if/elif/else, for and while. Indentation defines blocks; range() generates sequences.
- Functions use def name(parameters): with return. Know local versus global scope and default arguments.
- NumPy ndarray supports vectorised operations, shape, broadcasting and axis. pandas Series/DataFrame supports read_csv, head, info, loc/iloc, groupby. Matplotlib pyplot provides plot, scatter, hist, bar, xlabel, ylabel and title.
Worked example
Let scores = np.array([45, 67, 89]). scores.mean() gives 67.0 because (45+67+89)/3 = 67. scores + 5 gives [50, 72, 94] through broadcasting: 5 is added to every element without a loop. In pandas, df['marks'].fillna(df['marks'].median()) replaces missing marks with the median. Reasoning: the median is preferred when marks are skewed, because one very high or low value distorts the mean.
Traps that cost marks
Indentation is syntax, not style. Know // integer division versus / true division. Mutable default arguments share state across calls. Do not modify a list while iterating over it. NumPy slicing can return a view, not a copy. Avoid pandas chained assignment; use loc. Import plotting correctly as import matplotlib.pyplot as plt.