Python Data Types

Python Data Types are the identity of the values stored in variables. With the help of Python Data Types, we can define the type of variables.

There are lots of data types in Python Programming. They can be categorised like this:

  • Numbers
  • Strings
  • List
  • Tuples
  • Sets
  • Dictionary

Let’s learn about all these one by one with simple examples.


Python Datatypes – Numbers

If the single numeric value is stored in the variables, then its Data Types said to be Numbers. Numbers can be of following types:

  • Integer
  • Float
  • Complex

Integer: Non-decimal values are known as Integers. There is no effective limit of integers in Python. We can store large number of values.

Float: Such datatypes holds decimal values and can hold upto 12 decimals.

Complex: Complex number are those whose value is not a real number. For example, 10+3. It’s value is an imaginary number.

Example of Number Datatypes in Python

num_1 = 1312344334
num_2 = 12.312412414
num_3 = 2+5j
print(num_1)
print(num_2)
print(num_3)
Tutorials Class - Output Window

1312344334
12.312412414
(2+5j)

Note: There is an long dataype which is used to be in Previson version of Python 2.x . Now it is depricated in PYthon 3.x. So , don’t be confused.


Python Data Types – Strings

Strings are the sequence of characters. If a variable stores a single string value in it, then it is said to be a string. Most of the time strings are represented by single quote or double quotes such as “hello”.

Example of string data type

var_1 = "Welcome to the Tutorials Class"
var_2 = 'Welcome to the Tutorials Class'
print(var_1)
print(var_2)
Tutorials Class - Output Window

Welcome to the Tutorials Class
Welcome to the Tutorials Class


Python Lists

With the help of the list, we can store multiple values in a single variable. The list is a collection of data that can be ordered or changeable. The list can stores the duplicate elements as well. Lists are written within the square brackets such as []

.
Example of python list

my_list = [121, 323, 324, "Tutorials"]
print(my_list)
Tutorials Class - Output Window

[121, 323, 324, ‘Tutorials’]

To learn more about the lists, Click here.


Python Tuples

Like lists, tuples are sequences that are used to store multiple values. The only difference between lists and tuples is tuples can’t be modified. The list uses square brackets. On the other hand, tuples use parentheses ()

my_tuple = (121, 323, 324, "Tutorials")
print(my_tuple)
Tutorials Class - Output Window

(121, 323, 324, ‘Tutorials’)

To learn more about the Tuples, Click here.


Python Sets

Like lists and tuples, sets are also the collection of data. Unlike these, sets elements don’t have any specific order and index as well. To write the set just include the data within the curly braces {}


Example of python set

my_set = {"PHP", "Python", "MySQL"}
print(my_set)
Tutorials Class - Output Window

{‘MySQL’, ‘Python’, ‘PHP’}

Here you can see that the set appeared without any order because sets are unordered and unindexed.
To learn more about the Sets, Click here.


Python Dictionary

A Dictionary is also a collection of data in python. Unlike sets, Dictionaries are indexed but these are unordered and changeable as well.
Like sets these are written within the curly braces {} , but have some keys and values as each element.

Example of python dictionary

my_dictionary =	{
  "Title": "TutorialsClass",
  "Year": 2019,
  "Topic": "Dictionary"
}
print(my_dictionary)
Tutorials Class - Output Window

{‘Title’: ‘TutorialsClass’, ‘Yeat’: ‘2019’, ‘Topic’: ‘Dictionary’}

To learn more about the Dictionary, Click here.


Congratulations! Chapter Finished. Learn more about the similar topics:
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.