Crus4

logo

Python Data Types


Data Types in Python refer to the classification or categorization of data based on the type of value it holds. Python has several data types, which includes:

  1. Integers (int)
  2. Float
  3. Boolean
  4. Strings (str)
  5. List
  6. tuple
  7. set
  8. Dictionaries (dict)

Python Integers (int)

Integer data type in Python, includes all the whole numbers, both positive and negative, without a decimal point. For example, 2, -5, 0.

Python Floats

Python float data type includes all the numbers with a decimal point, including numbers with a fractional part. For example, 3.14159, -2.5, 5.0.

Python Booleans

Python Boolean data type can have one of two values. True or False.

Python Strings (str)

Python String data type (str) includes the sequences of characters enclosed in single or double quotes. For example, “hello”, ‘world’, “123”.

Python Lists (list)

Python list data type includes an ordered sequences of values, which can be of any data type, enclosed in square brackets. For example, [1, 2, 3], [“apple”, “banana”, “cherry”].

Python Tuples (tuple)

Python tuple data type are similar to lists, but they are immutable (cannot be modified), and are enclosed in parentheses. For example, (1, 2, 3), (“apple”, “mango”, “cherry”).

Note:- Lists are enclosed in square brackets and tuples are enclosed in parentheses.

Python Sets (set)

Python set data type is an unordered collection of unique items. Elements in set are separated with commas and are enclosed in curly braces {}. For example {“apple”, “mango”, “banana”}.

Python Dictionaries (dict)

Python dict data type is used to store an unordered collections of key-value pairs, enclosed in curly braces. For example, {“name”: “John”, “age”: 30}.


Python Data Types (with examples)