Lists are the first data structure you learn in Python. They are also the source of the most interview mistakes. These five problems test list behavior that most developers misunderstand until they get it wrong under pressure. Work through each one before reading the answer. a = [1, 2, 3, 4, 5] b = a[:] b.append(6) print(a) print(b) What do both lines print? Output: [1,2,3,4,5][1,2,3,4,5,6] a[:] creates a shallow copy. b is a new list object containing the same integer objects.
Is this you? As a journalist, you can create a free Muck Rack account to customize your profile, list your contact preferences, and upload a portfolio of your best work.
Claim your profile
Get in touch with Roghaye
Contact Roghaye, search articles and posts on X, monitor coverage, and track replies from one place.
Learn more about Muck Rack