Data types signify the type of data that python can deal with or different types of data that python variables can hold. Python has following standard data types.
1. Numbers
This data type represents numeric values and can be classified into following sub-types
A. int: This type refers to integer or whole numbers which are not fractions or which do not have a decimal such as 0, 28, -10 etc.
B. long: Whole numbers which are large and do not fit in the range of an integer should be stored as long. Octal and hexadecimal numbers are also stored as long. For differentiating between int and long data types, append an ‘l’ or ‘L’ to the number, Examples,
C. float: This data type refers to decimal numbers. Examples are 10.2, 11.0, 99.9234, -56.73 etc. These are also referred to as floating point numbers.
2. Strings
A sequence of characters is called a string in python. A string may be of one word or multiple words separated by a space. It may also span multiple lines. A string is always enclosed between single quotes(‘ and ‘) or double quotes(” and “). Examples are ‘Python’, “I am learning to code”, etc.
There is much more to learn about strings which is available here.
3. Lists
A list is a collection of items that may or may not be of same type. That is, a list can contain a string, an int, a float or it may be completely of string values. But often it is used as a collection of similar items. There can be a list of fruits, a list of courses, a list of scores and so on.
For more detailed content on list, redirect to this page.
4. Tuples
A tuple is similar to a list in that it is also a collection of items of same or different data types but it is different from a list as a tuple is immutable. This means that once a tuple is created it cannot be modified. More about tuples here.
5. Dictionaries
A dictionary consists of key-value pairs. Each key and value is separated with a colon(:) while key-value pairs are separated with a comma(,).
Example of a dictionary is {“name”: “Pacific”, “type”: “Ocean”, “name”: “Arabian”, “type”: “Sea”}. It is not mandatory for keys and values to be string. It is also not mandatory for keys and values to be of same type. Dictionaries can be read about in detail here.