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

Datatypes in Python

The document provides an overview of data types in Python, explaining the concept of data types, values, and the type() function. It details various data types including Numbers, Sequences (Strings, Lists, Tuples), Dictionaries, Sets, and Booleans, highlighting their characteristics and examples. The document serves as an educational resource for understanding the fundamental data types used in Python programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Datatypes in Python

The document provides an overview of data types in Python, explaining the concept of data types, values, and the type() function. It details various data types including Numbers, Sequences (Strings, Lists, Tuples), Dictionaries, Sets, and Booleans, highlighting their characteristics and examples. The document serves as an educational resource for understanding the fundamental data types used in Python programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

K.C.S.

KASI NADAR COLLEGE OF ARTS &


SCIENCE
(Belongs to S.V.H.N.A.Dharma Fund)

DATATYPES IN PYTHON

By,
Mrs.B.VIJAYALAKSHMI,
Assistant Professor,
Department Of Computer Science.
WHAT IS DATATYPE???

• Value :

 A Value can be any letter, number or string.

Eg, Values are 2, 42.0, and 'Hello, World!'. (These values


belong to different datatypes.)

• Data type:
 Every value in Python has a data type.

 It is a set of values, and the allowable operations on those


values.

• type() function is used to determine the type of datatype.


DATATYPES IN PYTHON
NUMBERS
• Number data type stores Numerical Values.
• This data type is immutable [i.e. values/items cannot be changed].
• Python supports integers, floating point numbers and complex numbers.
Integers Long Float Complex
They are often called as They are long integers. They are written with a They are of the form a+bj
integers or int. decimal point dividing the Where a and b are floats
integer and the fractional and j represents the square
They are positive or They can also be parts. root of -1(which is an
negative whole numbers represented in octal and imaginary number).
with no decimal points. hexa decimal
representation Real part of the number is
a, and the imaginary part is
b.

Eg : 65 Eg: 5692431L Eg : 56.778 Eg : 5+3i


SEQUENCE

• A sequence is an ordered collection of items, indexed by positive integers.


• It is a combination of mutable (value can be changed) and immutable
(values cannot be changed) datatypes.

• There are three types of sequence data type available in Python, they are
1. Strings

2. Lists

3. Tuples
STRINGS
• A String in Python consists of a series or sequence of characters.
Single quotes(' ') E.g., 'This a string in single quotes' ,
Double quotes(" ") E.g., "'This a string in double quotes'" ,
Triple quotes(""" """)E.g., """This is a paragraph. It is made up of multiple lines
and sentences."""
• Individual character in a string is accessed using a subscript(index).
• Strings are Immutable i.e the contents of the string cannot be changed after it
is created.
LISTS

• List is an ordered sequence of items. Values in the list are called


elements /items.
• It can be written as a list of comma-separated items (values) between
square brackets[].
• Items in the lists can be of different datatypes.
Eg : lt = [ 10, -20, 15.5, ‘ABC’, “XYZ” ]
TUPLES
• In tuple the set of elements is enclosed in parentheses ( ).
• A tuple is an immutable list.
• Once a tuple has been created, you can't add elements to a tuple or
remove elements from the tuple.
Benefit of Tuple:
• Tuples are faster than lists.
• If the user wants to protect the data from accidental changes, tuple
can be used.
• Tuples can be used as keys in dictionaries, while lists can't.
Altering the tuple data type leads to error.
Eg : tpl = ( 10, -20, 15.5, ‘ABC’, “XYZ” )
DICTIONARIES
• A dictionary maps keys to values.
• Lists are ordered sets of objects, whereas dictionaries are unordered sets.
• Dictionary is created by using curly brackets. i,e.{ }
• Dictionaries are accessed via keys and not via their position.
• The values of a dictionary can be any Python data type. So dictionaries
are unordered key-value pairs(The association of a key and a value is
called a key- value pair)
Eg : Creating a dictionary:
>>> food = {"ham":"yes", "egg" : "yes", "rate":450 }
SET :
• Python also provides two set types, set and frozenset.
• The set type is mutable, while frozenset is immutable.
• They are unordered collections of immutable objects.

BOOLEAN :
• The boolean data type is either True or False.
• In Python, boolean variables are defined by the True and False
keywords.
• The keywords True and False must have an Upper Case first letter.
THANK YOU!!!

You might also like