Ultimate Guide to Data Types in Python | Lists, Dictionaries, Strings and More

data types lists dictionaries tuples strings complex

DATA-TYPES IN PYTHON

Any Python programmer must know how to use the different data-types that Python offers. There is a huge variety of data-types, each of which is useful under certain circumstances. Some of them are used commonly, but this post will cover all that you need to know about all the different Python Data-Types.

Here is a quick and simple Mind Map to get you started with Data Types:

python data-types mind map float complex boolean sets dictionary string list tuple









Let's start with the NUMERIC DATA-TYPES

  1. INTEGER: The Integer Data-Type is used to handle integer values. Any number without a decimal point comes under Integer. For example: 523 is an integer.
  2. FLOAT: The Float Data-Type is used when you have a decimal point in your number. For example: 231.45 is a float.
  3. COMPLEX: The Complex Data-Type is used to handle any imaginary number or numbers of the form 'a + ib'. 
Now, what is the BOOLEAN DATA-TYPE ? The Boolean Data-Type is used to represent the True or False conditions. True and False are the two Boolean operators. 

Finally, the SEQUENCE or COLLECTION OF DATA data-types. We have 5 main data-types here:
  1. LISTS: Probably the most commonly used data-type to store a collection of data, Lists are mutable and can be used to store any number of elements all of same or different data-types. Lists are ordered and elements can be selected with the index. 
  2. TUPLES: Tuples are not very different from Lists, apart from the fact that Tuples are immutable, meaning that they cannot be edited once defined. 
  3. DICTIONARIES: Dictionaries are a collection of key-value pairs, where each key refers to a value. Keys must be unique and must be an immutable element, like a tuple, string or integer. Dictionaries are mutable and values can be changed or added after defining the dictionary. 
  4. SETS: Sets are, once again, very similar to lists but unlike lists, sets do not have a specific order. Every time you print a set, you can see a different order of the same elements. Sets do not allow item assignment. 
  5. STRINGS: Another very commonly used data-type, strings are a collection of characters and are therefore, considered as a collection of data. Strings are immutable, ordered and can be iterated. Python offers a lot of functions including the join function, the split function, capitalize function and many more such functions that help us do a lot with strings. 
So, that's all you need to know about data-types in Python. These data-types make up all programs, from a hello world program to an AI program. Now that you know what each data-type does, get coding...

If you have any comments or queries, do use the comment section to let me know and I will try my best to solve them and Do follow ThePygrammer if you find these posts useful.

This post has only the basics. If you think you are ready for the next level, check out these best selling books that will help you go from Beginner to Pro: 

 

If you want to check out some other programs: 
Meet The Math Module : Know more about the math module
Graphs with Python : Become an expert in graph-drawing with Python and Matplotlib




Comments

Post a Comment