1 / 7

Mutable Data Types in Python

This presentation is here to help you understand about the Mutable Data Type in Python, and it explains its components with programing example.

Download Presentation

Mutable Data Types in Python

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Data Types in Python Swipe

  2. Mutable Data Type in Python Note:- Mutable sequences can be changed after creation. Some of Python’s mutable data types are: lists, byte arrays, sets, and dictionaries. a.List b.Bytes arrays Mutable Data Types c.Sets d.Dictionaries

  3. List As you saw earlier, lists are mutable. Here’s another example using the append() method: a = list(('apple', 'banana', 'clementine')) print(id(a)) a.append('dates') print(id(a)) [Out:] 140372445629448 140372445629448

  4. Byte Arrays Byte arrays represent the mutable version of bytes objects. They expose most of the usual methods of mutable sequences as well as most of the methods of the bytes type. Items are integers in the range [0, 256). b = bytearray(b'python') print(id(b)) b.replace(b'p', b'P') print(id(b)) [Out:] 139963525979808 139963525979808

  5. Sets Python provides two set types, set and frozenset. They are unordered collections of immutable objects. c = set((‘San Francisco’, ‘Sydney’, ‘Sapporo’)) print(id(c)) c.pop() print(id(c)) [Out:] 140494031990344 140494031990344 As you can see, sets are indeed mutable. Later, in the Immutable Data Types section, we will see that frozensets are immutable.

  6. Dictionaries Represents an unordered collection of keys and values. The Dictionary data type is optimized for fast lookup of values. The following methods are available on instances of the Dictionary data type

  7. Topics for next Post Immutable Data Type in Python. Object Reusability in Python. Stay Tuned with

More Related