0% found this document useful (0 votes)
5 views1 page

Python Interview Study Notes: Core & Libraries

Uploaded by

Anish Kumar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

Python Interview Study Notes: Core & Libraries

Uploaded by

Anish Kumar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Python Interview Study Notes (Phase 1 + Phase 2)

Phase 1 – Python Core


Data Types: int, float, str, list, tuple, set, dict, bool.
Data Structures: Lists (mutable), Tuples (immutable), Sets (unordered), Dicts (key-value).
Recursion: Function calling itself. Example: Fibonacci via recursion.
Factorial: Recursive function returning n * fact(n-1).
Nested if-else: Reduces readability; replace with dict mapping or match-case.
Reverse String: Use loop: rev = ch + rev.
String Immutability: Strings cannot be changed in place.
Lists: Dynamic, heterogeneous, sliceable.
Sets: No duplicates, unordered.
Copy: Shallow copy copies references; deep copy copies nested data.
Dictionaries: Key-value pairs; fast lookup.
Merge Dict: {**d1, **d2} or d1 | d2.
Built-in Data Types: Numeric, Sequence, Set, Mapping, Boolean, NoneType.
Python in Data Science: Easy syntax, rich libraries, community support.
List vs Tuple: Mutable vs Immutable.
Keywords: if, else, def, class, try, except, etc.
Mutability: Mutable types change in place; immutables create copies.
Operators: Arithmetic, Logical, Comparison, Assignment, Bitwise.
Type Casting: Explicit (manual) vs Implicit (automatic).

Phase 2 – NumPy, Pandas, Matplotlib, Seaborn, Plotly


NumPy: Fast numerical operations using arrays. Supports broadcasting, slicing, reshaping.
Array Creation: [Link](), [Link](), [Link](), [Link]().
Array Ops: Element-wise add, multiply, matrix operations via [Link]().
Aggregation: mean, sum, min, max, std.
Pandas: DataFrame (2D), Series (1D). Used for data manipulation and analysis.
Read/Write: pd.read_csv(), to_csv().
Missing Data: dropna(), fillna().
Merge/Join: merge(), concat(), join().
GroupBy: Aggregation by column values.
Filtering/Sorting: df[df['col']>x], sort_values().
Visualization: [Link](), [Link]().
Matplotlib: Create plots using [Link](), [Link](), [Link]().
Customization: title(), xlabel(), ylabel(), legend().
Subplots: [Link](nrows, ncols).
Seaborn: Built on Matplotlib; easier and aesthetic ([Link], [Link]).
Plotly: Interactive charts using [Link](), [Link]().
Dash: Create web dashboards for data visualization.

Common questions

Powered by AI

Shallow copying a structure like a list or dictionary in Python means copying the structure itself but not the objects it contains, thus the references to the nested objects remain intact. A deep copy, on the other hand, creates a new independent copy of both the structure and all nested objects it contains, thus ensuring that modifications to the copied structure do not affect the original . Shallow copies are faster and use less memory than deep copies but require caution when dealing with references in nested data structures .

In Python, strings are immutable, meaning once they are created, their value cannot be altered in place. This immutability ensures that strings are more memory-efficient, as the same string literal can be reused across different sections of code, and leads to potentially fewer memory allocations. It also results in less error-prone code by avoiding accidental modifications. However, frequent string manipulations, such as concatenations in loops or constructing large strings, may incur performance penalties due to the need for creating new string objects .

Python’s built-in data types, such as integers, floats, strings, and collections like lists and dictionaries, provide the fundamental constructs needed for procedural programming by allowing straightforward manipulation of data with functions and loops . Additionally, Python supports object-oriented programming (OOP) with classes and objects, enabling encapsulation and inheritance, which are fundamental OOP principles. The ability to define methods and encapsulate state within objects makes Python data types versatile for various programming paradigms .

Explicit type casting in Python, also known as type conversion, involves manually converting a variable from one type to another using functions like int(), float(), and str(), which allows the programmer to control type changes and ensure compatibility in expressions and operations . Implicit type casting happens automatically when Python converts a smaller data type to a larger one (like from int to float) to avoid data loss. Explicit casting is suitable for precision control and when specific type transformations are needed, whereas implicit casting is used when Python safely handles type conversions without programmer intervention .

Python lists are mutable, ordered collections that allow duplicate elements, making them suitable for sequential data processing where order matters . Sets, on the other hand, are mutable but unordered collections that automatically eliminate duplicates, offering efficient membership tests and set operations like union and intersection . Lists provide flexibility for dynamic operations like appending, while sets provide performance advantages in operations like membership checking due to hash table implementation .

Recursive functions offer elegant solutions for problems like the Fibonacci sequence, providing a clear and concise way to express algorithms that have a natural recursive structure . They facilitate easier reasoning about the algorithm's progression but can lead to high memory consumption and potential stack overflow due to deep recursive calls. The lack of tail call optimization in Python further exacerbates this issue. Alternative iterative solutions, while potentially less intuitive, may offer improved performance and resource utilization by avoiding the overhead of multiple stack frames .

NumPy is optimized for fast array operations and is ideal for performing mathematical computations, such as element-wise operations and linear algebra, thanks to its efficient implementation of multidimensional arrays . Pandas, built on top of NumPy, is more suited for data manipulation tasks, offering higher-level structures like DataFrames and Series that enable complex data analysis, grouping, filtering, and handling of missing data . Together, they form a powerful duo where NumPy underpins numerical capabilities and Pandas adds user-friendly data manipulation and analysis functionalities, crucial for versatile data science workflows .

Python dictionaries excel in implementing algorithms that require fast key-based lookups and associations due to their efficient hash table implementation, leading to average O(1) complexity for insertions and lookups . This efficiency makes dictionaries suitable for use cases such as caching results of expensive functions, counting occurrences, and managing relationships between data items, offering a significant speed advantage over lists and tuples, which would require linear or binary search techniques. Lists or tuples can become unwieldy or inefficient for high-frequency lookups or modifications, whereas dictionaries provide more structured and maintainable solutions .

Recursion in Python involves defining functions that call themselves to solve problems by breaking them down into smaller instances, such as calculating a factorial or Fibonacci series. This approach provides elegant solutions for problems defined recursively but may lead to performance overheads like increased memory use due to stack frames . Iterative solutions, using loops, usually offer better performance and are more understandable for many programmers due to their straightforward execution flow but can be less intuitive for complex recursive problem representations .

Python's simple syntax and readability make it accessible for programmers of all skill levels, which extends its adoption in data science by making complex computational scripts more understandable and maintainable. Its rich library ecosystem—highlighted by libraries like NumPy for numerical operations, Pandas for data manipulation, Matplotlib and Seaborn for data visualization—offers comprehensive tools that streamline and expedite data analysis processes, thus enhancing productivity and innovation in data projects . The extensive community also provides valuable support and continuous development .

You might also like