Python Data Types

In this tutorial you will learn about the Python Data Types and its application with practical example.

Python Data Types

Variables are used to represent reserved memory locations that is used to store values, when we create a variable we are a suppose to allocate some memory space for that variable. Every variable have data type associated to it, a data type for a variable defines –

Table Of Contents
  • The amount of memory space allocated for variables.
  • A data type specifies the possible values for variables.
  • The operations that can be performed on variables.

Python is a dynamically-typed language, which means it is not required beforehand to declare a variable explicitly to use in a program. Python interpreter sets the variable’s data type based on the value assigned to it, data type is changed if the variable value is set to different data type value.

Python has following built-in Data Types –

Python Numbers:- The Number data type is used to hold the numeric values. Python supports following numerical data types –

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.

Python Boolean:- The Boolean data type is used to represent the truth values, which can be either True or False.

Python String:- A string variable is used to hold series or sequence of characters – letters, numbers, and special characters. In Python, string is represented using single quotes or double quotes.

Python List:- A list is an ordered series of comma-separated values, each of the value as termed as Item. A list variable is defined by having values separated by commas and enclosed within square brackets ([]). A list can hold values of different data types.

Python Tuple:- Tuple is an ordered sequence of comma-separated values (items or elements). Tuples are same as list, but the only difference is that tuples are immutable. Once a tuple is created their elements and size can not be changed.A Tuple is defined within parentheses () where items are separated by commas.

Example:-

Output:-

Python Set:- In Python, set is an unordered collection of unique elements or items. A Set is defined by comma-separated values inside braces { }.

Example:-

Output:-

Python Dictionary:- In Python, Dictionary is an unordered collection of key-value pairs. Dictionary is similar to associative arrays or hashes consist of key-value pairs. Dictionary is defined by using curly braces ({ }) and values can be assigned and accessed using square braces ([]).

Example:-

 

In this tutorial we have learn about the Python Data Types and its application with practical example. I hope you will like this tutorial.