In Python, the following are the commonly used data types:
- int (integers) – a whole number that can be positive, negative, or zero. For example: -10, 0, 100.
- float (floating-point numbers) – a decimal number that can be positive, negative, or zero. For example: -10.0, 0.0, 100.0.
- str (strings) – a sequence of characters. For example: “Hello, World!”, “123”, “abc”.
- bool (Boolean values) – a data type with two possible values, True or False. Used to represent binary choices or logical values.
- list – an ordered collection of objects. Lists are mutable, meaning the elements of a list can be changed. For example: [1, 2, 3, 4, 5].
- tuple – an ordered, immutable collection of objects. Tuples cannot be changed after they are created. For example: (1, 2, 3, 4, 5).
- dict (dictionaries) – an unordered collection of key-value pairs. Dictionaries are mutable, meaning their elements can be changed. For example: {“name”: “John”, “age”: 30}.
- set – an unordered collection of unique elements. Sets are mutable and can be used to remove duplicates from a list. For example: {1, 2, 3, 4, 5}.
- None – a special constant used to represent the absence of a value. For example, when a function doesn’t return a value, it is equivalent to returning None.