0% found this document useful (0 votes)
32 views

Data Types in Python 6 Standard Data Types in P

This document discusses different data types in Python that are important for data science. It describes the main numeric, string, list, tuple, set, and dictionary data types. For each data type it provides the definition, syntax examples, and common operations like concatenation, slicing, indexing, updating, etc. The goal is to help beginners understand these fundamental Python data types that form the basis of programming in Python.

Uploaded by

asik6361877967
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

Data Types in Python 6 Standard Data Types in P

This document discusses different data types in Python that are important for data science. It describes the main numeric, string, list, tuple, set, and dictionary data types. For each data type it provides the definition, syntax examples, and common operations like concatenation, slicing, indexing, updating, etc. The goal is to help beginners understand these fundamental Python data types that form the basis of programming in Python.

Uploaded by

asik6361877967
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Data Types in Python You Need to know

at the Beginning of your Data Science


Journey

Home

Prashant Sharma — Published On August 3, 2021 and


Last Modified On July 26th, 2022
Beginner Programming Python

This article was published as a part of


the Data Science Blogathon

Introduction
In this article, you’ll learn about Python Data
Types and their applications while we writing
the python programs in an optimized manner.
You will learn ranging from what they’re,
their syntax, and also see the examples to use
them in Programs. Python is a language that
needs no introduction. It’s incredibly
powerful, versatile, fast and it’s easy to find
out.
Python is one of the languages that’s
witnessing incredible growth and recognition
year by year. Python is an interpreted
programming language that is object-
oriented used for general-purpose
programming. In this article, we are going to
learn about different data types in the
python language.

What are data types?


Data types are the classification or
categorization of knowledge items. It
represents the type useful that tells what
operations are often performed on specific
data. Since everything is an object in Python
programming, data types are classes and
variables are instances (object) of those
classes.
Data types are an important concept within
the python programing language. Every value
has its own python data type, in the python
programming language. The classification of
knowledge items or to place the info value
into some kind of data category is named
Data Types. It helps to know what quiet
operations are often performed on a worth.

Python has six standard


Data Types:-
Numeric
String
List
Tuple
Set
Dictionary

Image Source: link

Let’s discuss the above data types one by


one:-
Numeric Data Type:-
In Python, numeric data type represents the
data that has a numeric value. The numeric
value can be an integer, floating number, or
even complex number. These values are
defined as int, float, and complex classes in
Python.

Integers – This data type is represented with the help of

int class. It consists of positive or negative whole numbers

(without fraction or decimal). In Python, there’s no limit to

how long integer values are often.

Example:-
Python Code:

@Santhosh-Reddy1/…
Open on Replit
A Nix (beta) repl b…

0 Run 6

Float – This type is represented by the float


class. It is a true number with floating-point
representation. It is specified by a decimal
point. Optionally, the character e or E
followed by a positive or negative integer
could even be appended to specify scientific
notation.

Example:-

b = 1.5
print(b, "is of type", type(b))
Output: 1.5 is of type

Complex Numbers – Complex numbers are


represented by complex classes. It is
specified as (real part) + (imaginary part)j, For
example – 4+5j.

Example:-

c = 8+3j
print(c, "is a type", type(c))
Output: (8+3j) is a type

String Data Type:-


The string is a sequence of Unicode
characters. A string may be a collection of 1
or more characters put during a quotation
mark, double-quote, or triple quote. It can be
represented using an str class.

Example:-

string1= “Hello World”


print(string1)
output: Hello World

We can perform several operations in


strings like Concatenation, Slicing, and
Repetition.
Concatenation: It includes the operation of
joining two or more strings together.

Example:-

String1 = "Hello"
String2 ="World"
print(String1+String2)
Output: Hello World

Slicing: Slicing is a technique for extracting


different parts of a string.

Example:-

String1 = "Hello"
print(String1[2:4])
Output: llo

Repetition:

It means repeating a sequence of instructions


a certain number of times.

Example:-

Print(String1*5)
Output: HelloHelloHelloHelloHello

List Data Type:-


A list is formed(or created) by placing all the
items (elements) inside square brackets [ ],
separated by commas.
It can have any number of items and they
may or may not be of different types (integer,
float, string, etc.).
A list is mutable, which suggests we will
modify the list
Example:

List1 = [3,8,7.2,"Hello"]
print("List1[2] = ", List[2])
Output: List1[2] = 7.2
print("List1[1:3] = ", List[1:3])
Output: List1[1:3] = [8, 7.2]

Updating the list:- we can update the list.

List1[3] = "World"
#If we print the whole list, we can see
print(List1)
Output: [3, 8, 7.2, ‘World’]

Tuple Data Type:-


A tuple is defined as an ordered collection of
Python objects. The only difference between
tuple and list is that tuples are immutable i.e.
tuples can’t be modified after it’s created. It is
represented by tuple class. we can represent
tuples using parentheses ( ).

Example:

Tuple = (25,10,12.5,"Hello")
print("Tuple[1] = ", Tuple[1])
Output: Tuple[1] = 10
print("Tuple[0:3] =", Tuple[0:3])
Output: Tuple[0:3] = (25,10,12.5)

Set Data Type:-


A set is an unordered collection of items.
Every set element is exclusive (no duplicates)
and must be immutable (cannot be changed).

Example:

Set = {4,3,6.6,"Hello"}
print(Set)
Output: {‘Hello’, 3, 4, 6.6}

As the set is an unordered collection,


indexing will be meaningless. Hence the
slicing operator [ ] doesn’t work.

Set[1] = 12
Output: TypeError

Dictionary Data Type:-


In Python, Dictionary is an unordered
collection of data values, which is used to
store data values like a map, which, unlike
other Data Types that hold only a single value
as an element, a Dictionary consists of key-
value pair. Key-value is provided within the
dictionary to form it more optimized. In the
representation of a dictionary data type,
each key-value pair during a Dictionary is
separated by a colon: whereas each key’s
separated by a ‘comma’.

Syntax:
Key:value

Example:

Dict1 = {1:'Hello',2:5.5, 3:'World'}


print(Dict1)
Output: {1: ‘Hello’, 2: 5.5, 3: ‘World’

We can retrieve the value by using the


following method:

Example:

print(Dict[2])
Output: 5.5

We can update the dictionary by following


methods as well:

Example:

Dict[3] = 'World'
print(Dict)
Output:
{1: ‘Hello’, 2: 5.5, 3: ‘World’}

Conclusion
If you’re reading this text, you’re probably
learning Python or trying to become a
Python developer. Learning Python or the
other programing language begins by
understanding the concepts that are a basic
part of its foundation.
Hope you want to have understood the
varied classifications of Python Data Types
by now, from this text .
About The Author
Prashant Sharma
Currently, I Am pursuing my Bachelors of
Technology( B.Tech) from Vellore Institute of
Technology. I am very enthusiastic about
programming and its real applications
including software development, machine
learning, and data science.

Hope you like the article. If you want to


connect with me then you can connect on:

Linkedin

or for any other doubts, you can


send a mail
to me also

The media shown in this article are not


owned by Analytics Vidhya and are used at
the Author’s discretion.

Related

Python Certification Python vs Scala for


Guide: Best Python Apache Spark: Which is
Certifications For All Better?
Levels in 2023 (Free &
Paid)

Introduction to Python
Programming
(Beginner’s Guide)

blogathon data types

python data types

About the Author

Prashant Sharma
Currently, I Am pursuing my Bachelors of
Technology( B.Tech) from Vellore Institute of
Technology. I am very enthusiastic about
programming and its real applications
including software development, machine
learning and data science.

Our Top Authors

Download
Analytics Vidhya App for the Latest
blog/Article

Next Post

Building a Data Pipeline with PySpark


and AWS

One thought on "Data


Types in Python You Need
to know at the Beginning of
your Data Science Journey"
Programmer says:
October 11, 2022 at 9:51 pm

Good morning, As i was reading


this article i found an error for
the following example output:
String1 = "Hello"
print(String1[2:4]) Output: llo
The output should be: ll Best
regards, Anonymous
programmer
Reply

Leave a Reply
Your email address will not be published.
Required fields are marked *

Comment

Name*

Email*

Website

Notify me of follow-up comments by


email.

Notify me of new posts by email.

Submit

Top Resources

30 Best Data Science Books to Read


in 2023

Swati Sharma - FEB 28, 2023

We use cookies on Analytics Vidhya websites to deliver our


services, analyze web traffic, and improve your experience on
the site. By using Analytics Vidhya, you agree to our Privacy
© Copyright 2013-2023 Analytics Vidhya.
Policy and Terms of Use. Accept
Privacy Policy Terms of Use Refund Policy

You might also like