Python Interview Questions

Python Interview Questions - Data Types & Operators

Prepare for Python interviews with detailed questions on data types, collection types, and operators.

By TechCoder TeamLast updated: 2026-06-02
In a Nutshell

Prepare for Python interviews with detailed questions on data types, collection types, and operators. This interview-focused guide covers essential python interview questions - data types & operators concepts for technical interviews.

Python Interview Questions – Level 1: Data Types & Operators

Master the core data structures and operators that form the backbone of Python programming.


41. What are integers in Python?

Integers are whole numbers.

[!NOTE] Technical Detail: In Python 3, integers have arbitrary precision, meaning they can be as large as your computer's memory allows. This is different from languages like C++ where integers are typically 32 or 64-bit.

42. What are floats?

Floats represent real numbers with a decimal point. They are implemented using double precision (64-bit) in C.

43. What are complex numbers?

Consist of a real and an imaginary part, written as x + yj. They are useful in scientific computing and signal processing.

44. What is a string?

A string is an immutable sequence of Unicode characters.

45. How are strings stored?

Python 3 uses an optimized storage system (PEP 393). It stores strings in the most compact format possible:

  • 1 byte/char (Latin-1)
  • 2 bytes/char (UCS-2)
  • 4 bytes/char (UCS-4)

46. What is string slicing?

The syntax is string[start:stop:step].

[!TIP] Pro Tip: Slicing always creates a new string object. s[::-1] is the common way to reverse a string in a single line.

47. What is string immutability?

Strings cannot be modified in-place. If you try to change a character, Python raises a TypeError. This is done for security, caching (interning), and to allow strings to be used as dictionary keys.

48. What are lists?

Lists are mutable, ordered sequences. They are implemented as dynamic arrays in CPython.

[!IMPORTANT] Complexity: Appending to a list is O(1) (amortized), but inserting at the beginning is O(n) because all existing elements must be shifted.

49. How are lists different from tuples?

  • Lists: Mutable, slower, larger memory footprint (due to over-allocation).
  • Tuples: Immutable, faster, smaller memory footprint.

50. What are tuples?

Tuples are immutable sequences. They are often used to group related "fields" together (like a database row).

51. What are sets?

Sets are unordered collections of unique items. They are implemented using a hash table.

[!TIP] Complexity: Checking if an item exists in a set ('x' in my_set) is O(1) on average, compared to O(n) for a list.

52. What is a dictionary?

A dictionary is a collection of key-value pairs.

[!CAUTION] Interview Trap: Keys must be hashable (immutable). This means you can use a string, int, or tuple as a key, but NOT a list or another dictionary.

53. Difference between list, tuple, set, and dict?

FeatureListTupleSetDict
OrderedYesYesNoYes (since 3.7)
MutableYesNoYesYes
DuplicatesYesYesNoNo (Keys)

54. What are arithmetic operators?

+, -, *, /, // (floor division), % (modulus), ** (exponent).

55. What are comparison operators?

==, !=, >, <, >=, <=.

56. What are logical operators?

and, or, not. They use short-circuit evaluation (e.g., if the first part of an and is False, the second part isn't even checked).

57. What are assignment operators?

=, +=, -=, *=, etc.

58. What are bitwise operators?

& (AND), | (OR), ^ (XOR), ~ (NOT), <<, >>. These operate on the binary representation of integers.

59. What is operator precedence?

The order of operations (PEMDAS). Parentheses > Exponent > Multiplication/Division > Addition/Subtraction.

60. What is type casting?

Converting data from one type to another.

  • Implicit: Done by Python (e.g., 5 + 1.0 = 6.0).
  • Explicit: Done by you (e.g., int("10")).

61. What is implicit casting?

Refer to question 60. It's an automatic conversion by the interpreter to prevent data loss.

num_int = 10      # Integer
num_float = 2.5   # Float

# Implicit casting: int + float -> float
result = num_int + num_float 
print(result)     # 12.5
print(type(result)) # <class 'float'>

62. What is explicit casting?

Refer to question 60. It's a manual conversion using functions like float(), str(), etc.

x = 10
y = "20"

# Explicit casting: converting str to int
result = x + int(y)
print(result) # 30

63. What is membership operator?

in and not in. They check if an element is a member of a sequence.

fruits = ["apple", "banana"]
print("apple" in fruits)      # True
print("cherry" not in fruits) # True

[!TIP] Performance: Membership checks are O(1) for sets and dictionaries, but O(n) for lists and strings.

64. What is identity operator?

is and is not.

a = [1, 2, 3]
b = [1, 2, 3]
c = a

print(a == b)  # True (Same values)
print(a is b)  # False (Different objects)
print(a is c)  # True (Same object)

[!IMPORTANT] Interview Question: What's the difference between == and is? Answer: == compares values (equality), while is compares memory addresses (identity).

65. What is indexing?

Accessing an element by its position. Python supports negative indexing, where -1 is the last element.

text = "Python"
print(text[0])   # 'P' (First element)
print(text[-1])  # 'n' (Last element)

66. What is slicing?

Refer to question 46.

67. What is len()?

Returns the number of items in a collection. It's an O(1) operation because Python collections store their size.

items = [1, 2, 3, 4]
print(len(items)) # 4

68. What is max()?

Returns the largest item. Works on any iterable with comparable elements.

print(max([10, 50, 20])) # 50
print(max("Hello"))      # 'o' (Lexicographically largest)

69. What is min()?

Returns the smallest item.

print(min([10, 50, 20])) # 10
print(min("Hello"))      # 'H' (Lexicographically smallest)

70. What is sum()?

Calculates the total of numeric items. You can also provide a start value: sum([1, 2], 10) # 13.

numbers = [1, 2, 3, 4]
print(sum(numbers))      # 10
print(sum(numbers, 10))  # 20 (starts adding from 10)

71. What is sorted()?

Returns a new sorted list. It uses Timsort (an O(n log n) algorithm).

nums = [3, 1, 4, 1, 5]
print(sorted(nums))             # [1, 1, 3, 4, 5]
print(sorted(nums, reverse=True)) # [5, 4, 3, 1, 1]

72. What is any()?

Returns True if at least one element is truthy.

print(any([False, False, True]))  # True
print(any([0, 0, 0]))             # False

73. What is all()?

Returns True if all elements are truthy.

print(all([True, True, True]))    # True
print(all([True, False, True]))   # False

74. What is hash()?

Returns the hash value. Only immutable objects are hashable.

print(hash("hello"))   # -123... (Some integer)
# print(hash([1, 2]))  # TypeError: unhashable type: 'list'

75. What is enumerate()?

Returns an iterator of (index, value) tuples. Much cleaner than using range(len(list)).

colors = ["red", "green"]
for index, value in enumerate(colors):
    print(f"{index}: {value}")
# Output:
# 0: red
# 1: green

76. What is zip()?

Combines multiple iterables into one iterator of tuples.

names = ["Alice", "Bob"]
ages = [25, 30]
# [('Alice', 25), ('Bob', 30)]
print(list(zip(names, ages))) 

[!NOTE] If the iterables have different lengths, zip stops at the shortest one by default. Use itertools.zip_longest to change this.

77. What is range()?

In Python 3, range() is a lazy object (a generator-like object) that produces numbers on demand. It consumes very little memory regardless of the range size.

# start, stop (exclusive), step
print(list(range(5)))        # [0, 1, 2, 3, 4]
print(list(range(1, 10, 2))) # [1, 3, 5, 7, 9]

78. What is eval()?

Evaluates a string as a Python expression.

x = 10
# Evaluates the string expression
print(eval("x + 5")) # 15

[!CAUTION] Security Risk: Never use eval() on untrusted input (like user data), as it allows execution of arbitrary code!

79. What is ord()?

Converts a single character to its integer Unicode code point.

print(ord("A"))  # 65
print(ord("€"))  # 8364

80. What is chr()?

Converts an integer Unicode code point back to a character.

print(chr(65))    # 'A'
print(chr(97))    # 'a'