Exploring Data Types of python

As we practiced the python installation and get to started to used python in development and we understood the variable declaration in python in my last article. If you have not checked till now then I would be recommended to check my last articles, Here are the link Installation and uses of python and Variable declaration of python.

Now in this tutorial, we will learn what are the data types are available in python? Do not be worry about the uses of those data types right now. We will explain in detail in the upcoming tutorial. For this time being just try to understand these are the data types that we can use in the python development. So let’s get started to learn data types of python.

Python Data Types are used to define the type of a variable. In python there are five data types are available.

1. Numbers

Numbers is the data type in python. A Number means it having numeric values for example int, float, long and complex. Let’s see the uses of number with the help of example for better understanding.

Type Format Description
int a = 10 Signed Integer
long a = 345L (L) Long integers, they can also be represented in octal and hexadecimal
float a = 45.67 (.) Floating point real values
complex a = 3.14J (J) Contains integer in the range 0 to 255.

2. String

A string is a sequence of characters. Python supports Unicode characters. Generally, strings are represented by either single or double quote.

3. List

Lists are a very useful variable type in Python. A list can contain a series of values. List variables are declared by using brackets [ ] following the variable name. As we know in Java or Kotlin that List can hold anyone data types at one declaration. But here in python, it is the good thing that List can hold any type in one declaration. It could be a list, string, tuple or dictionary etc.

4. Tuple

A tuple is another data type which is a sequence of data similar to the list.  Tuples are fixed in size once they are assigned. In Python, the fixed size is considered immutable as compared to a list that is dynamic and mutable. Tuples are defined by parenthesis ().

Some of the good things to notice about the tuple.

  1. Tuples have no append or extend method. So the elements cannot be removed or add in a tuple.
  2. Tuples are faster than lists. It is good and safer to define product which is fixed.

5. Dictionary

Python Dictionary is an unordered sequence of data of key-value pair form. It is similar to the hash table type in java. Dictionaries are written within curly braces in the form key:value.  This is a very powerful datatype to hold a lot of related information that can be associated through keys. It is very useful to retrieve data in an optimized way among a large amount of data. In Dictionaries the Key must be unique.

Dictionaries are created by using braces { } with pairs separated by a comma (,) and the key values associated with a colon(:). Let’s see an example.

So these are the data types are available in python. We have understood that how we can use this data types in python. In my next tutorial, we will focus on basic conditional feature and their uses in python.

If you are wondering to learn Android then Please Learn from Android category and Wondering to lean Kotlin then Kotlin Category will help you.

Please do subscribe your email to get the newsletter on this blog on below and if you like this post then do not forget to share like and comment on below section.

Happy coding 🙂

I am a very enthusiastic Android developer to build solid Android apps. I have a keen interest in developing for Android and have published apps to the Google Play Store. I always open to learning new technologies. For any help drop us a line anytime at contact@mobologicplus.com

Leave a Reply

Your email address will not be published. Required fields are marked *