DEV Community

Cover image for Python Shots! - Data Types
Aman Jain
Aman Jain

Posted on

Python Shots! - Data Types

Python Data Types :

  • None
  • Numeric
    • int (num = 2)
    • float (num = 2.5)
    • complex (num = 1 + 2j)
    • bool (is_num = True)
  • sequence
    • List - [1,2,3]
    • Tuple - (1,2,3)
    • Set - {1,2,3}
    • String - ( str = "aman" )
    • Range - ( range(10) )
  • map
    • Dictionary - {"key":"value"}

Description in Brief

  1. List

    • [10,20,30]=> to store list of elements
    • mutable/can update value
    • used when you need to update values time to time
  2. Tuple

    • (1,34,56,7,89,5) => to store list of elements
    • indexing from 0
    • immutable/ can not update values
    • good and fast while looping through of getting data as it can't be updatable
  3. Set

    • {23,56,78,90,54} => to store list of elements
    • no indexing
    • stores unique elements only no repeatation
    • fast for searching as it uses hash table concept
  4. Dictionary

    • {"key":"value"} => store elements in key value pairs
    • custom indexing
    • used to deal with complex data like data inside data

Top comments (0)