Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Differences Between Python's Mutable and Immutable Types (Summary)

Now you have a deep understanding of how mutable and immutable data types internally work in Python. In general, mutable types allow in-place changes to their values, while immutable types don’t. Mutability is a fundamental feature that really influences which data types are appropriate for each specific problem.

Learning about mutable and immutable data types is, therefore, a vital skill to have as a Python programmer.

In this video course, you’ve learned:

  • How mutability and immutability work under the hood in Python
  • Which immutable and mutable built-in data types exist in Python
  • What common mutability-related gotchas can affect your code and how to prevent them
  • What techniques allow you to control mutability in custom classes
Download

Course Slides (.pdf)

2.0 MB
Download

Sample Code (.zip)

7.8 KB

00:00 Well done! You’ve made it to the end of this course, and as you can see in the lovely graphic, there are some examples of the data types you’ve come across in the course, some of which are mutable and some of which are immutable.

00:12 So let’s summarize what you’ve done in the course. You’ve learned the difference between mutability and immutability. Every object in Python has an identity, and that is set when you create the object. The identity never changes.

00:26 However, the value of that object can change if the object is mutable. For an immutable data type, the value cannot change either. That is also fixed. That’s the key difference between a mutable and an immutable object.

00:42 You’ve explored the built-in data types in Python, some of which are mutable like lists, dictionaries, and sets. And then there were the immutable ones like integers, floats, or tuples.

00:56 And finally, you learned how to identify and importantly, now you know how to avoid some of the common mutability-related gotchas. These pitfalls you can get because of how mutable objects can change their values, even though their references might remain the same.

01:15 And as often is the case, there’s a lot more to say about mutable and immutable types. If you want to read more, there’s the article which accompanies this video course, “Python’s Mutable vs Immutable Types: What’s the Difference?” And you can also read more about data types in “Basic Data Types in Python”.

01:33 You have an article and a video course to dive more into data types.

01:39 I hope you enjoyed this course, and now you’re ready to spot mutable and immutable types and to use them effectively in your code.

Become a Member to join the conversation.