Complete Guide On Data Types In Python

Kanalsoni
Analytics Vidhya
Published in
5 min readSep 27, 2020

In Python, there are total six data types. They are:

  1. NUMERIC
  2. LISTS
  3. TUPLES
  4. DICTIONARY
  5. SET
  6. STRINGS

NUMERIC DATA TYPE:

Numeric data types are used to store numeric values. Numeric data type is IMMUTABLE. That means; they can’t be modified or changed further.

Numeric data type includes the conversion which is given as below:

  • Type int(x) is used to convert x to a simple integer.
  • Type long(x) is used to convert x to a long integer.
  • Type float(x) is used to convert x to a floating-point number.

Moreover, Numeric data type conversions. They are:

As I have presented you the syntax and explanations of Numeric data type functions, let’s move ahead and apply all the above functions in the program.

Click here to download numericdatatype.py

LIST DATA TYPE:

Lists are an important data type. They are basically an organized collection of different or same objects. They are same as arrays. They are denoted by []. They are MUTABLE. That means, they can be changed or modified further. They can have heterogeneous data types in them. That means, they can have same or different data types together.

Accessing Elements: Accessing elements in lists is done by using Indexes. INDEX is basically the address in which the data which we want is stored.

List Slicing: Lists can be sliced. SLICING is a feature in Python which enables accessing parts of sequences like strings, lists and tuples. You can also use slicing for modifying or deleting elements of mutable data types.

Built-in List Functions & Methods:

Python includes following list methods:

So, I have hereby presented the program of Lists which covers every method and function used in it Have a look at it!

Click here to see listsprogram.py

TUPLE DATA TYPE:

Tuples are basically similar as the lists. They are denoted by (). They are IMMUTABLE. That means, they can’t be changed or modified further. This immutable nature makes them work more fast than lists. They are returned using the parenthesis.

Tuples can be accessed using Index and also can be Sliced.

When we want to have a tuple as a single element, make sure that it’s always with comma (,) at the end.

Elements in the tuple can be changed if the data type in the list is mutable.

Built-in Tuple Functions

Let’s see the complete program on tuples.

Click on tuples.py

DICTIONARY DATA TYPE:

Dictionary is also called dict. It is a data type that contains an unorganized collection of the data in form of the key-value pair. Thus, dictionaries are the data structure that stores the data in some specific format. They are denoted by {} curly brackets. The keys in dictionaries can be of any immutable data type like numeric, frozenset, strings, etc. and the value can hold any of the data types from all. The values can be accessed using the respective keys. The keys need to be unique/different. If there’s more than one identical key, then the values are overridden. This process is also called “Collision”.

Dictionaries don’t have any order so they are scattered around the memory.

Dictionary data type is MUTABLE.

Built-in Dictionary Functions & Methods:

Python includes the following dictionary methods that are given below:

Click on the .py file to see the complete program on dictionaries: dictionaries.py

THE SET DATA TYPE:

SETS are the unordered gatherings of the different/unique elements. They are mutable. That means they can be modified or changed further. They are denoted by {}. Now let’s focus on methods of sets.

Built-in Set Functions & Methods:

Python includes following Set methods:

Click on the .py file to see the complete program on sets: sets.py

STRING DATA TYPE:

Strings are the collection of different or same characters. Or we can say that Strings are the sequences of the character data. String type in python is written short as str. Strings are written under the single(‘) or the double(“) quotation marks. Strings are IMMUTABLE or can say that they can’t be modified further or changed further. They are denoted in () round parenthesis.

Strings can also be accessed using Index and can also be Sliced. Let’s now focus on the built-in methods and functions of the Strings.

Built-in String Functions

Click on strings.py

Hurray! We have finally completed our data types. Hope you’ve enjoyed data types and are now able to practice it by yourself. We’ll now step further in the next stories into the new topic of our basic python. Till then, Have a great day! Practice it well!

For more Python learning; visit on: https://wethepythonians.wordpress.com/

--

--