Posts

Showing posts from April, 2018

Tuple Data Type in Python

Image
  Concept Tuple  is a collection which is  immutable,  ordered and unchangeable. Allows duplicate members Code Example Example 1: >>> t = () >>> t () >>> type(t) <class 'tuple'> >>> t = (10, 20.35, 'Hello', [1, 2]) >>> t (10, 20.35, 'Hello', [1, 2]) Example 2: >>> t = (10, 20.35, 'Hello', [1, 2]) >>> len(t) 4 Get Help

Dict Comprehension in Python

Image
  Code Example Example 1: d = {i:i for i in range(1, 6)} print(d) Output: {1: 1, 2: 2, 3: 3, 4: 4, 5: 5}   Example 2: d = {i:[i, i+1] for i in range(6)} print(d) Output: {0: [0, 1], 1: [1, 2], 2: [2, 3], 3: [3, 4], 4: [4, 5], 5: [5, 6]}   Example 3: d = {i:i**2 for i in range(6)} print(d) Output: {0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25} Get Help