Data types in Python
Introduction of Python: Python is a high-level object-oriented indentation programming language that is a readable, general-purpose, and versatile programming language that abstracts low-level complexities, operates as an interpreted language with cross-platform compatibility boasts an extensive standard library, fosters a strong community and ecosystem, supports object-oriented programming with dynamic typing, and serves as a go-to choice for both beginners and experienced programmers, making it applicable across a wide spectrum of applications.
Integer (int): This data type is used to represent whole numbers. In Python, for example, you can declare an integer variable like this: X=5
- Float (float): Floats are used to represent numbers with a decimal point. For instance: y=3.15
- String (str): Strings are used to represent text. You can declare a string variable like this:
name = "John". - Boolean (bool): Booleans have only two possible values,
TrueorFalse, and are often used for conditional statements and comparisons. we can say as ‘1' or ‘0'. - List: A list is a collection of values, and it can hold various data types. In Python, a list is created using square brackets, like this:
my_list = [1, 2, 3, "apple"]. - Dictionary: A dictionary is a collection of key-value pairs. Keys must be unique, and values can be of any data type. In Python, dictionaries are declared using curly braces, like this:
my_dict = {"name": "Alice", "age": 30}. - Tuple: A tuple is similar to a list but is immutable, meaning its elements cannot be changed once it’s created. Tuples are often used for data that should not be modified. In Python, tuples are declared with parentheses:
my_tuple = (1, 2, 3). - Set: A set is an unordered collection of unique values. Sets are commonly used for tasks like removing duplicates from a list and they are mutable. In Python, sets are created with curly braces or the
set()constructor:my_set = {1, 2, [11,12,13,14]}.
Get Sameeramd’s stories in your inbox
Join Medium for free to get updates from this writer.






