Python Data Types

Python Programming Training Certification

Flexible Hours

100 Assignments

Instructor Led online Training

50 LMS Access

24X7 Support

100% Skill Level

Enquire Now

4.9 out of 1000+ Ratings
Best Python Institute for Learning Python Course & Training, Live Project Training in Python with Django, Data Science and AI, Interview Assistance, Expert Coaching Trainers. Python Certification & Interview Assistance! Get free demo now!

Course Overview

Python is one of the world’s top programming languages used today and Python training has become the most popular training across individuals. Training Basket’s Python Training & Certification course covers basic and advanced Python concepts and how to apply them in real-world applications.Python is a flexible and powerful open-source language that is easy to learn and consists of powerful libraries for data analysis and manipulation. Our Python training course content is curated by experts as per the standard Industry curriculum. The curriculum, coding challenges and real-life problems cover data operations in Python, strings, conditional statements, error handling, shell scripting, web scraping and the commonly used Python web framework Django. Take this Python training and certification course and become job-ready now.

Python Data Types

Variables can hold values, and every value has a data-type. Python is a dynamically typed language; hence we do not need to define the type of the variable while declaring it. The interpreter implicitly binds the value with its type.

  • a = 5

The variable a holds integer value five and we did not define its type. Python interpreter will automatically interpret variables a as an integer type.

Python enables us to check the type of the variable used in the program. Python provides us the type() function, which returns the type of the variable passed.

Consider the following example to define the values of different data types and checking its type.

  • a=10
    b=”Hi Python”
    c = 10.5
    print(type(a))
    print(type(b))
    print(type(c))

Output:

  • type ‘int’
    type ‘str’
    type ‘float’
Standard data types

A variable can hold different types of values. For example, a person’s name must be stored as a string whereas its id must be stored as an integer.

Python provides various standard data types that define the storage method on each of them. The data types defined in Python are given below.

Numbers
Sequence Type
Boolean
Set
Dictionary

In this section of the tutorial, we will give a brief introduction of the above data-types. We will discuss each one of them in detail later in this tutorial.

Numbers

Number stores numeric values. The integer, float, and complex values belong to a Python Numbers data-type. Python provides the type() function to know the data-type of the variable. Similarly, the isinstance() function is used to check an object belongs to a particular class.

Python creates Number objects when a number is assigned to a variable. For example;

  • a = 5
    print(“The type of a”, type(a))

    b = 40.5
    print(“The type of b”, type(b))

    c = 1+3j
    print(“The type of c”, type(c))
    print(” c is a complex number”, isinstance(1+3j,complex))

Output:

  • The type of a
    The type of b
    The type of c
    c is complex number: True

Python supports three types of numeric data.

  • Int – Integer value can be any length such as integers 10, 2, 29, -20, -150 etc. Python has no restriction on the length of an integer. Its value belongs to int
  • Float – Float is used to store floating-point numbers like 1.9, 9.902, 15.2, etc. It is accurate upto 15 decimal points.
  • complex – A complex number contains an ordered pair, i.e., x + iy where x and y denote the real and imaginary parts, respectively. The complex numbers like 2.14j, 2.0 + 2.3j, etc.
Sequence Type

String

The string can be defined as the sequence of characters represented in the quotation marks. In Python, we can use single, double, or triple quotes to define a string.

String handling in Python is a straightforward task since Python provides built-in functions and operators to perform operations in the string.

In the case of string handling, the operator + is used to concatenate two strings as the operation “hello”+” python” returns “hello python”.

The operator * is known as a repetition operator as the operation “Python” *2 returns ‘Python Python’.

The following example illustrates the string in Python.

Example – 1

  • str = “string using double quotes”
    print(str)
    s = ””’A multiline
    string”’
    print(s)

Output:

  • string using double quotes
    A multiline
    string

Consider the following example of string handling.

Example – 2

  • str1 = ‘hello javatpoint’ #string str1
    str2 = ‘ how are you’ #string str2
    print (str1[0:2]) #printing first two character using slice operator
    print (str1[4]) #printing 4th character of the string
    print (str1*2) #printing the string twice
    print (str1 + str2) #printing the concatenation of str1 and str2

Output:

  • he
    o
    hello javatpointhello javatpoint
    hello javatpoint how are you
List

Python Lists are similar to arrays in C. However, the list can contain data of different types. The items stored in the list are separated with a comma (,) and enclosed within square brackets [].

We can use slice [:] operators to access the data of the list. The concatenation operator (+) and repetition operator (*) works with the list in the same way as they were working with the strings.

Consider the following example.

  • list1 = [1, “hi”, “Python”, 2]
    #Checking type of given list
    print(type(list1))

    #Printing the list1
    print (list1)

    # List slicing
    print (list1[3:])

    # List slicing
    print (list1[0:2])

    # List Concatenation using + operator
    print (list1 + list1)

    # List repetation using * operator
    print (list1 * 3)

Output:

  • [1, ‘hi’, ‘Python’, 2]
    [2]
    [1, ‘hi’]
    [1, ‘hi’, ‘Python’, 2, 1, ‘hi’, ‘Python’, 2]
    [1, ‘hi’, ‘Python’, 2, 1, ‘hi’, ‘Python’, 2, 1, ‘hi’, ‘Python’, 2]

Tuple

A tuple is similar to the list in many ways. Like lists, tuples also contain the collection of the items of different data types. The items of the tuple are separated with a comma (,) and enclosed in parentheses ().

A tuple is a read-only data structure as we can’t modify the size and value of the items of a tuple.

Let’s see a simple example of the tuple.

  • tup = (“hi”, “Python”, 2)
    # Checking type of tup
    print (type(tup))

    #Printing the tuple
    print (tup)

    # Tuple slicing
    print (tup[1:])
    print (tup[0:1])

    # Tuple concatenation using + operator
    print (tup + tup)

    # Tuple repatation using * operator
    print (tup * 3)

    # Adding value to tup. It will throw an error.
    t[2] = “hi”

Output:


  • (‘hi’, ‘Python’, 2)
    (‘Python’, 2)
    (‘hi’,)
    (‘hi’, ‘Python’, 2, ‘hi’, ‘Python’, 2)
    (‘hi’, ‘Python’, 2, ‘hi’, ‘Python’, 2, ‘hi’, ‘Python’, 2)

    Traceback (most recent call last):
    File “main.py”, line 14, in
    t[2] = “hi”;
    TypeError: ‘tuple’ object does not support item assignment

Dictionary

Dictionary is an unordered set of a key-value pair of items. It is like an associative array or a hash table where each key stores a specific value. Key can hold any primitive data type, whereas value is an arbitrary Python object.

The items in the dictionary are separated with the comma (,) and enclosed in the curly braces {}.

Consider the following example.

  • d = {1:’Jimmy’, 2:’Alex’, 3:’john’, 4:’mike’}# Printing dictionary
    print (d)

    # Accesing value using keys
    print(“1st name is “+d[1])
    print(“2nd name is “+ d[4])

    print (d.keys())
    print (d.values())

Output:

  • 1st name is Jimmy
    2nd name is mike
    {1: ‘Jimmy’, 2: ‘Alex’, 3: ‘john’, 4: ‘mike’}
    dict_keys([1, 2, 3, 4])
    dict_values([‘Jimmy’, ‘Alex’, ‘john’, ‘mike’])

Boolean

Boolean type provides two built-in values, True and False. These values are used to determine the given statement true or false. It denotes by the class bool. True can be represented by any non-zero value or ‘T’ whereas false can be represented by the 0 or ‘F’. Consider the following example.

  • # Python program to check the boolean type
    print(type(True))
    print(type(False))
    print(false)

Output:



  • NameError: name ‘false’ is not defined

Set

Python Set is the unordered collection of the data type. It is iterable, mutable(can modify after creation), and has unique elements. In set, the order of the elements is undefined; it may return the changed sequence of the element. The set is created by using a built-in function set(), or a sequence of elements is passed in the curly braces and separated by the comma. It can contain various types of values. Consider the following example.

  • # Creating Empty set
    set1 = set()

    set2 = {‘James’, 2, 3,’Python’}

    #Printing Set value
    print(set2)

    # Adding element to the set

    set2.add(10)
    print(set2)

    #Removing element from the set
    set2.remove(2)
    print(set2)

Output:

  • {3, ‘Python’, ‘James’, 2}
    {‘Python’, ‘James’, 3, 2, 10}
    {‘Python’, ‘James’, 3, 10}

Recently Trained Students

Jessica Biel

– Infosys

My instructor had sound Knowledge and used to puts a lot of effort that made the course as simple and easy as possible. I was aiming for with the help of the ZebLearn Online training imparted to me by this organization.

Richard Harris

– ITC

I got my training from Zeblearn in the Python Certification Training, I would like to say that say he is one of the best trainers. He has not even trained me but also motivated me to explore more and the way he executed the project, in the end, was mind-blowing.


Candidate’s Journey During Our Training Program

Card image cap

Expert’s Advice & Selection of Module

Choosing the right type of module for the training is half the battle & Our Team of experts will help & guide you.

Card image cap

Get Trained

Get Trained & Learn End to End Implementation from our Expert Trainer who are working on the same domain.

Card image cap

Work on Projects

We Do make our student’s work on multiple case studies , scenario based tasks & projects in order to provide real-time exposure to them.

Card image cap

Placements

We have a dedicated placement cell in order to provide placement assistance & relevant interviews to our candididates till selection

Placement Partner

×

Leave your details

×

Download Course Content