Python data types are used to classify the different types of data that can be stored in Python variables. There are six built-in data types in Python:
Numeric data types: These data types are used to store numeric values, such as integers, floating-point numbers, and complex numbers. The numeric data types in Python are:
int
: Stores signed integers of non-limited length.float
: Stores floating-point numbers with double precision, which means that they can have up to 15 decimal places.complex
: Stores complex numbers, which are numbers that have both a real and an imaginary component.
Sequence data types: These data types are used to store ordered collections of data. The sequence data types in Python are:
list
: A mutable sequence of data that can be of any type.tuple
: An immutable sequence of data that can be of any type.string
: A sequence of characters.
Set data type: This data type is used to store unordered collections of unique data. The set data type in Python is:
set
: A mutable set of unique data that can be of any type.
Dictionary data type: This data type is used to store unordered collections of key-value pairs. The dictionary data type in Python is:
dict
: A mutable dictionary of key-value pairs, where the keys can be of any type and the values can be of any type.
Difference Between List And Tuple
The main difference between lists and tuples is that lists are mutable, while tuples are immutable. This means that lists can be changed after they are created, while tuples cannot.
Here is a table summarizing the other key differences between lists and tuples:
Feature | List | Tuple |
Mutability | Mutable | Immutable |
Size | Can have a variable size | Has a fixed-size |
Representation | Enclosed in square brackets ([] ) | Enclosed in parentheses (() ) |
Common uses | Storing and manipulating data that needs to be changed | Storing and manipulating data that needs to be kept constant |
Data Structure
Data Structures are a way of organizing data so that it can be accessed more efficiently depending on the situation. Data Structures are fundamentals of any programming language around which a program is built. Python helps to learn the fundamentals of these data structures in a simpler way as compared to other programming languages.
Lists Python Lists are just like the arrays, declared in other languages which is an ordered collection of data. It is very flexible as the items in a list do not need to be of the same type
Tuple Python Tuple is a collection of Python objects much like a list but Tuples are immutable in nature i.e. the elements in the tuple cannot be added or removed once created. Just like a List, a Tuple can also contain elements of various types.
Dictionary Python dictionary is like hash tables in any other language with the time complexity of O(1). It is an unordered collection of data values, used to store data values like a map, which, unlike other Data Types that hold only a single value as an element, Dictionary holds the key: value pair. Key-value is provided in the dictionary to make it more optimized
#python #DevOps #cloud #CloudEngineer #DevOpsChallenge #90DaysOfDevOps