Skip to main content

Python 3 Part 4 - Understanding tuple data structure

 Understanding Tuple data structure

Table of content

  1. Tuple
  2. How to define tuple
  3. Access tuple elements
  4. Tuple containing mutation
  5. Tuple methods

Tuple

Tuple is an immutable inbuilt data structure, once created can't be modified. We can define tuple using () round Bracktes in Python.

How to define tuple?

Access tuple elements

We index the tuple to access element

Tuple cannot be modified.

Tuple containing mutation

Tuple are immutable but can contain mutable data elements like list. We can loop on tuple using for loop.

Methods

1) tuple.count(x) : returns count of occurrence of element. The number of times the element is present in the tuple.

2) tuple.index(x) : returns index of value. (first occurrence from left)


Thank you folks. If you like this Python 3 post, please do checkout my other post on  Django with Python 3 series

Most viewed

Understanding ASCII / Unicode character encoding format

Computer stores everything in binary format. The process of converting a value into binary is called Encoding and the the process of converting value from binary is called Decoding. value --> binary  ::     Encoding  binary --> value   ::    Decoding for example: A number 12 is stored in its binary format as below.               12 ---> 00001100 but how are the characters are stored? If we want to store a character 'a' what formatting should be used ? It easiest way is to map the characters to number and store the binary format of that number. So, the character 'a' is represented as number 97 is stored as 1100001.  ASCII: In ASCII encoding format, 128 unique characters are identified and mapped with numbers (mostly English). One byte is used to represent all the characters. It uses 7 bits to represent numeric value 0 to 127 (total 128 characters).  The most significant bit is a...