You are on page 1of 14

Identifying and

Converting
Data Types
At the end of the discussion,
we would be able to…

 Define Different Data Types in Python


 Convert Data Types in Python
 Demonstrate the skill of converting Data
Types accurately
What are the different
types of Data Types
in Python?
Data Types

Every value in Python has a data type.


Since everything is an object in Python, data
types are actually classes, and variables
are instances (object) of these classes.

Numbers in Python can either be


plain integers, long integers,
floating point numbers, or complex
numbers. They are defined as
int, float, and complex class.
Data Types Example: 10, 1000, 8008135
Int
Example: 10.0, 1000.5
Float
None Complex
Example: 10j, 1000.5j
Bool
Numeric
Example:
List
Tuple
Integers can be of any length; it is
Sequence
only limited by the memory available.
A floating point number is accurate
Set
up to 15 decimal places.
Integer and floating points are
String
separated by decimal points.
Sequence Data types

List [ ] Mutable

Tuple ( ) Immutable

Set { } Mutable

String Immutable
“ “
List – is an ordered sequence of items. It is one of the
most used data types in Python and very flexible. All items
in a list do not need to be of the same type.

Items separated by commas are enclosed within brackets [].

We can use a slicing operator [] to extract an item or a


range of items from a list. Index starts from zero.

Example:

The colon (: )
inside the index
refers to the
range in the
given data set
Tuple – is an ordered sequence of items, same as a list.
The only difference is that a tuple is immutable. A tuple
once created, cannot be modified.

It is used to write-protect data and is usually faster than


a list as it cannot change dynamically. It is defined
within parentheses () where items are separated by commas.

Example:
Set – is an unordered collection of unique items. It is
defined by values separated by comma inside braces {}.
The items in a set are not ordered.
Example:

Since a set is an unordered


collection, indexing has no meaning.
We can
perform set
operations
like union,
intersection
Every set element is unique and
must be immutable. However, a on two
set itself is mutable sets.
String – is a sequence of characters. We can use single quotes
(“’ ‘”)or double quotes (““ ””)to represent strings.
Multiline strings can be denoted using triple quotes (““” “””).
Like list and tuple, slicing operator [] can be used with string.

Example:

Hello world!

0 1 2 3 4 5 6 7 8 9 10 11
Converting different
Data Types
FIRST,
IDENTIFY THE
DATA TYPE

type() function
Converting!

Error:
THE
END

You might also like