DATATYPES IN PYTHON
Data types are the classification or categorization of data items. It represents the kind of value that tells what operations can be performed on a particular data. Since everything is an object in Python programming, data types are actually classes and variables are instance (object) of these classes.
Get Bhavatharani’s stories in your inbox
Join Medium for free to get updates from this writer.
Following are the standard or built-in data type of Python:
- Numeric
- Sequence Type
- List
- Tuple
- Set
- Dictionary
Numeric:
In Python, numeric data type represent the data which has numeric value. Numeric value can be integer, floating number or even complex numbers. These values are defined as int, float and complex class in Python.
- Integers — This value is represented by int class. It contains positive or negative whole numbers (without fraction or decimal). In Python there is no limit to how long an integer value can be.
- Float — This value is represented by float class. It is a real number with floating point representation. It is specified by a decimal point. Optionally, the character e or E followed by a positive or negative integer may be appended to specify scientific notation.
- Complex Numbers — Complex number is represented by complex class. It is specified as (real part) + (imaginary part)j. For example — 2+3j
String:
A sequence of Unicode characters makes up the string. A string is a group of one or more characters enclosed in a quotation mark, double-quote, or triple-quote. An str class can be used to represent it. Different types of operations can be performed like concatenation which is the adding of two or more strings together, slicing which is the technique of extracting different parts from a string and repetition which is a set of instructions repeated a set number of times.
List:
All the elements of a list are enclosed in square brackets [ ] and separated by commas.
It can include any number of elements, which may or may not be of various sorts (integer, float, string, etc.).
A list can be changed.
Tuple:
An ordered collection of Python objects is known as a tuple. The only difference between a tuple and a list is that tuples are immutable, meaning they can’t be changed after they’ve been generated. The tuple class is used to represent it. Parentheses can be used to express tuples ( ).
Set:
A set is an unsorted group of elements. Each set element must be unique (no duplication) and immutable. Because the set is an unordered collection, indexing is futile.
Dictionary:
In Python, a Dictionary is an unordered collection of data values, similar to a map, that is used to store data values. Unlike other Data Types that carry only a single value as an element, a Dictionary contains key-value pairs. To make the dictionary more optimized, key-value pairs are provided. Each key-value pair is separated by a colon in the representation of a dictionary data type, whereas each key is separated by a ‘comma’.







