In Python, there are several built-in data types that can be used to store different kinds of data. Some of the commonly used data types in Python are:
-
Integer (int): Represents whole numbers, both positive and negative, without any decimal point. Example: x = 5
-
Float: Represents real numbers with a decimal point. Example: x = 3.14
-
String (str): Represents a sequence of characters enclosed in single quotes (‘ ‘) or double quotes (“ “). Example: x = “Hello, World!”
-
Boolean (bool): Represents a value of either True or False. Example: x = True
-
List: Represents an ordered collection of items enclosed in square brackets ([]). The items can be of different data types. Example: x = [1, 2, “three”, True]
-
Tuple: Represents an ordered collection of items enclosed in parentheses (()). The items can be of different data types. Unlike lists, tuples are immutable, meaning their values cannot be changed once assigned. Example: x = (1, 2, “three”, True)
-
Dictionary: Represents an unordered collection of key-value pairs enclosed in curly braces ({}). Each key-value pair is separated by a colon (:), and the keys must be unique. Example: x = {“name”: “John”, “age”: 25, “city”: “New York”}
-
Set: Represents an unordered collection of unique items enclosed in curly braces ({}). Sets do not allow duplicate values. Example: x = {1, 2, 3, 4}
These are some of the commonly used data types in Python.
Loading...