Essential Python Interview Concepts: Data Types, Typing, and Duck Typing

Core Python Data Types

Python supports multiple fundamental data types. Numeric types include integers (int), floating-point numbers (float), and complex numbers (complex). The string (str) type handles textual data. Sequence types such as lists (list) and tuples (tuple) store collections of elements. Dictionaries (dict) provide key-value pair storage with efficient lookups, while sets (set) handle unique element collections.

Lists are mutable and allow element modification:

items = [10, 'apple', 3.14]
items[1] = 'orange'  # Modify element

Dictionaries enable value access via keys:

person = {'name': 'Alice', 'age': 30}
print(person['name'])  # Output: 'Alice'

Python Typing Characteristics

Python is dynamically typed, meaning variable types are resolved at runtime without explicit declaration. This provides flexibility during development.

Python is also strongly typed, preventing implicit type conversions. Operations between incompatible types raise errors:

# Raises TypeError due to string and integer concatenation
output = 'Score: ' + 100

Explicit type enforcement reduces unexpected behavior.

Duck Typing Principle

Duck typing allows objects to be used based on their behavior rather than their type. If an object supports expected methods or attributes, it can be used interchangeably:

class Bird:
    def sound(self):
        print("Chirp")

class Toy:
    def sound(self):
        print("Beep")

def emit_sound(entity):
    entity.sound()

emit_sound(Bird())  # Output: Chirp
emit_sound(Toy())   # Output: Beep

This approach promotes polymorphism and code reusability.

Assignment, Shallow Copy, and Deep Copy Differences

Assignment creates a reference to an existing object. Shallow copy constructs a new object but shares references to nested objects. Deep copy generates a completely independent copy of the original object and all its nested elements.

__init__ vs __new__ Methods

__new__ constructs an object instance, while __init__ initializes its state. __new__ controls creation, and __init__ handles post-creation setup.

Variables, Objects, and References

In Python, all entities are objects. Variables act as references to these objects, similar to labels pointing to memory locations.

Tags: python Data Types Duck Typing Type Systems Object-Oriented Programming

Posted on Fri, 09 Oct 2026 16:08:30 +0000 by tracivia