Skip to main content

Lists and Mutability

  • Chapter
  • First Online:
An Introduction to Python and Computer Programming

Part of the book series: Lecture Notes in Electrical Engineering ((LNEE,volume 353))

  • 14k Accesses

Abstract

This chapter introduces lists, a sequential container type that is mutable. Lists are the first mutable type introduced in the book; they can be regarded as modifiable counterparts of tuples. Two ways of changing a list object are introduced, and common tips and pitfalls on working with list are discussed. In addition, the concept of attributes and methods is introduced.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 99.00
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 129.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info
Hardcover Book
USD 179.99
Price excludes VAT (USA)
  • Durable hardcover edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Notes

  1. 1.

    The values of variables that are bound to immutable objects can change, because the assignment statement can change the binding between identifiers and objects. For example, when the statement \(x=x+1\) or \(x+\!\!=1\) is executed, the identifier x is unbound from its previous value \(o_1\) and bound to a new object \(o_2\), the value of which is \(o_1+1\). In this process, neither the object \(o_1\) nor the object \(o_2\) changes, but the value of the variable x changes. In memory, the assignment statement changes only the binding table, but not the number objects.

  2. 2.

    Due to the caching of small numbers introduced in Chap. 2, the integers 1, 2, 3, the string ‘a’ and the object None are not copied. The figure is for illustration of a simple recursive copying mechanism.

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Yue Zhang .

Rights and permissions

Reprints and permissions

Copyright information

© 2015 Springer Science+Business Media Singapore

About this chapter

Cite this chapter

Zhang, Y. (2015). Lists and Mutability. In: An Introduction to Python and Computer Programming. Lecture Notes in Electrical Engineering, vol 353. Springer, Singapore. https://doi.org/10.1007/978-981-287-609-6_7

Download citation

  • DOI: https://doi.org/10.1007/978-981-287-609-6_7

  • Published:

  • Publisher Name: Springer, Singapore

  • Print ISBN: 978-981-287-608-9

  • Online ISBN: 978-981-287-609-6

  • eBook Packages: EngineeringEngineering (R0)

Publish with us

Policies and ethics