Skip to main content

In Python, like in all programming languages, data types are used to classify one particular type of data. This is important because the specific data type you use will determine what values you can assign to it and what you can do to it (including what operations you can perform on it).

In this tutorial, we will go over the important data types native to Python. This is not an exhaustive investigation of data types, but will help you become familiar with what options you have available to you in Python.

 

python data types

Data types in Python

Every value in Python has a data type. Since everything is an object in Python programming, data types are actually classes, and variables are instance (object) of these classes.

There are various data types in Python. Some of the important types are listed below

Data Types in Python

  1. Python Numbers

  2. Python List

  3. Python Tuple

  4. Python Strings

  5. Python Set

  6. Python Dictionary 

  7. Python boolean

python data types

Python Numbers

There are three numeric types in Python:

  • int - Int, or integer, is a whole number, positive or negative, without decimals, of unlimited length.
  • float - Float, or "floating point number" is a number, positive or negative, containing one or more decimals. Float can also be scientific numbers with an "e" to indicate the power of 10.
  • complex - Complex numbers are written with a "j" as the imaginary part.

List

Lists are used to store multiple items in a single variable.

Lists are one of 4 built-in data types in Python used to store collections of data, the other 3 are tuples, sets and dictionary, all with different qualities and usage.

Lists are created using square brackets [ ]

Tuple

Tuples are used to store multiple items in a single variable.

Tuple is one of 4 built-in data types in Python used to store collections of data, the other 3 are list, set, and dictionary, all with different qualities and usage.

A tuple is a collection which is ordered and unchangeable.

Tuples are written with round brackets ( ).

Strings

Strings in python are surrounded by either single quotation marks, or double quotation marks.

'hello' is the same as "hello".

You can display a string literal with the print() function.

Set

Sets are used to store multiple items in a single variable.

Set is one of 4 built-in data types in Python used to store collections of data, the other 3 are list, tuple , and dictionary , all with different qualities and usage.

A set is a collection which is both unordered and unindexed.

Sets are written with curly brackets { }.

Dictionary

Dictionaries are used to store data values in key:value pairs.

A dictionary is a collection which is unordered, changeable and does not allow duplicates.

Dictionaries are written with curly brackets, and have keys and values: { k:v }.

Boolean Values

In programming you often need to know if an expression is True or False.

You can evaluate any expression in Python, and get one of two answers, True or False.

When you compare two values, the expression is evaluated and Python returns the Boolean answer.

Video Tutorial
Tags

About

Elix is a premium wordpress theme for portfolio, freelancer, design agencies and a wide range of other design institutions.