SlideShare a Scribd company logo
BASIC DATA TYPES IN PYTHON
PROF. SUNIL D. CHUTE
HEAD DEPT OF COMPUTER SCIENC
M.G. COLLEGE ARMORI
BASIC DATA TYPES IN PYTHON
 Data types are the classification or
categorization of data items. It represents the
kind of value that tells what operations can
be performed on a particular data. Since
everything is an object in Python
programming, data types are actually classes
and variables are instance (object) of these
classes.
One way to categorize these basic data types is in
one of four groups:
 Numeric: int, float and the less frequently
encountered complex
 Sequence: str (string), list and tuple
 Boolean: (True or False)
 Dictionary: dict(dictionary) data type, consisting
of (key, value) pairs
NOTE: It's important to point out that Python usually doesn't require you
to specify what data type you are using and will assign a data type to
your variable based on what it thinks you meant.
An equally important thing to point out is that Python is a
"loosely/weakly typed" programming language, meaning that a variable
can change its type over the course of the program's execution, which
isn't the case with "strongly typed" programming languages (such as
Java or C++).
Basic data types in python
NUMERIC DATA TYPES
These data types are fairly straight-forward and represent
numeric values. These can be decimal values, floating point
values or even complex numbers.
 Integer Data Type - int
The int data type deals with integers values. This means
values like 0, 1, -2 and -15, and not numbers like 0.5, 1.01, -
10.8, etc.
If you give Python the following code, it will conclude that a is
an integer and will assign the int data type to it:
>>> x = 5
>>> type(x)
<class 'int'>
We could have been more specific and said something along these
lines, to make sure Python understood our 5 as an integer, though,
it'll automatically do this exact same thing under the hood:
>>> x = int(5)
>>> type(x)
<class 'int‘>
It's worth noting that Python treats any sequence of numbers (without a
prefix) as a decimal number. This sequence, in fact, isn't constrained.
That is to say, unlike in some other languages like Java, the value of
the int doesn't have a maximum value - it's unbounded.
The sys.maxsize may sound counterintuitive then, since it implies that that's
the maximum value of an integer, though, it isn't.
>>> x = sys.maxsize
>>> x
2147483647
This appears to be a 32-bit signed binary integer value, though, let's see
what happens if we assign a higher number to x:
>>> x = sys.maxsize
>>> x+1
2147483648
In fact, we can even go as far as:
>>> y = sys.maxsize + sys.maxsize
>>> y
4294967294
The only real limit to how big an integer can be is the memory
of the machine you're running Python on.
 Prefixing Integers
What happens when you'd like to pack a numeric value in a
different form? You can prefix a sequence of numbers and tell
Python to treat them in a different system.
More specifically, the prefixes:
 0b or 0B - Will turn your integer into Binary
 0o or 0O - Will turn your integer into Octal
 0x or 0X - Will turn your integer into Hexadecimal
 # Decimal value of 5
>>> x = 5
>>> x
5
 # Binary value of 1
>>> x = 0b001
>>> x
1
 # Octal value of 5
>>> x = 0o5
>>> x
5
 # Hexadecimal value of 10
>>> x = 0x10
>>> x
16
FLOATING POINT DATA TYPE - FLOAT
 The float type in Python designates a floating-point number. float values
are specified with a decimal point. Optionally, the
character e or E followed by a positive or negative integer may be
appended to specify scientific notation
Ex.1 >>> 4.2 4.2
>>> type(4.2)
<class 'float'>
Ex.2 >>> 4.
4.0
Ex.3 >>> .2
0.2
Ex.4>>> .4e7 4000000.0
>>> type(.4e7)
<class 'float'>
Ex.5>>> 4.2e-4
COMPLEX NUMBERS
 Complex numbers are specified as <real
part>+<imaginary part>j.
Ex. >>> 2+3j
(2+3j)
>>> type(2+3j)
<class 'complex'>
STRINGS
 Strings are sequences of character data. The string
type in Python is called str.
 String literals may be delimited using either single or
double quotes. All the characters between the opening
delimiter and matching closing delimiter are part of the
string:
Ex.>>> print("I am a string.")
I am a string.
>>> type("I am a string.")
<class 'str'>
Ex.>>> print('I am too.')
I am too.
>>> type('I am too.')
<class 'str'>
 A string in Python can contain as many characters as you
wish. The only limit is your machine’s memory resources.
A string can also be empty:
Ex. >>> ''
''
 What if you want to include a quote character as part of
the string itself? Your first impulse might be to try
something like this:
Ex.>>> print('This string contains a single quote (')
character.')
SyntaxError: invalid syntax
Ex. >>> mystring = "This is not my first String"
>>> print (mystring);
This is not my first String
 to join two or more strings.
Ex.>>> print ("Hello" + "World");
HelloWorld
Ex. >>> s1 = "Name Python "
>>> s2 = "had been adapted "
>>> s3 = "from Monty Python"
>>> print (s1 + s2 + s3)
Name Python had been adapted from Monty
Python
 use input() function
Ex.>>> n = input("Number of times you
want the text to repeat: ")
Number of times you want the text to
repeat:
>>> print ("Text"*n);
TextTextTextTextText
 Check existence of a character or a sub-
string in a string
Ex.>>> "won" in "India won the match"
True
PYTHON LIST DATA TYPE
 List is an ordered sequence of items. It is one of
the most used datatype in Python and is very
flexible. All the items in a list do not need to be
of the same type.
 Declaring a list is pretty straight forward. Items
separated by commas are enclosed within
brackets [ ].
Ex. a = [1, 2.2, 'python']
We can use the slicing operator [ ] to extract an
item or a range of items from a list. The index
starts from 0 in Python.
Basic data types in python
PYTHON TUPLE DATA TYPE
 Tuple is an ordered sequence of items same
as a list. The only difference is that tuples are
immutable. Tuples once created cannot be
modified.
 Tuples are used to write-protect data and are
usually faster than lists as they cannot
change dynamically.
 It is defined within parentheses () where
items are separated by commas.
Ex. t = (5,'program', 1+3j)
 We can use the slicing operator [] to extract
items but we cannot change its value.
PYTHON SET DATA TYPE
 Set is an unordered collection of unique
items. Set is defined by values separated by
comma inside braces { }. Items in a set are
not ordered.
 A set is created by placing all the items
(elements) inside curly braces {}, separated
by comma, or by using the built-
in set() function.
 It can have any number of items and they
may be of different types (integer, float, tuple,
string etc.). But a set cannot have mutable
Basic data types in python
Basic data types in python
PYTHON DICTIONARY DATA TYPE
 Python dictionary is an unordered collection
of items. Each item of a dictionary has
a key/value pair.
 It is generally used when we have a huge
amount of data. Dictionaries are optimized
for retrieving data. We must know the key to
retrieve the value.
 In Python, dictionaries are defined within
braces {} with each item being a pair in the
form key:value. Key and value can be of any
type.
Basic data types in python
CONVERSION BETWEEN DATA TYPES
Basic data types in python

More Related Content

PDF
Introduction to Python
Mohammed Sikander
 
PPTX
Python Data-Types
Akhil Kaushik
 
PPTX
Python
Gagandeep Nanda
 
PDF
Python made easy
Abhishek kumar
 
PPTX
Phython Programming Language
R.h. Himel
 
PPTX
Python ppt
Rachit Bhargava
 
PPTX
Python programming introduction
Siddique Ibrahim
 
PPTX
Python basics
Hoang Nguyen
 
Introduction to Python
Mohammed Sikander
 
Python Data-Types
Akhil Kaushik
 
Python made easy
Abhishek kumar
 
Phython Programming Language
R.h. Himel
 
Python ppt
Rachit Bhargava
 
Python programming introduction
Siddique Ibrahim
 
Python basics
Hoang Nguyen
 

What's hot (20)

PPSX
Modules and packages in python
TMARAGATHAM
 
PPTX
Python basics
RANAALIMAJEEDRAJPUT
 
PDF
Datatypes in python
eShikshak
 
PPT
Class and object in C++
rprajat007
 
PDF
Python - the basics
University of Technology
 
PDF
Lesson 02 python keywords and identifiers
Nilimesh Halder
 
PPTX
Introduction to the basics of Python programming (part 1)
Pedro Rodrigues
 
PPTX
Conditionalstatement
RaginiJain21
 
PPTX
Python Tutorial Part 1
Haitham El-Ghareeb
 
PPTX
Python ppt
Anush verma
 
PDF
Python tuple
Mohammed Sikander
 
PPT
structure and union
student
 
PPTX
Values and Data types in python
Jothi Thilaga P
 
PPTX
Oop c++class(final).ppt
Alok Kumar
 
PPTX
Static Data Members and Member Functions
MOHIT AGARWAL
 
PPTX
Datatype in c++ unit 3 -topic 2
MOHIT TOMAR
 
PPTX
Python Functions
Mohammed Sikander
 
PDF
Python set
Mohammed Sikander
 
PDF
What is Python Lambda Function? Python Tutorial | Edureka
Edureka!
 
PPTX
Python: Modules and Packages
Damian T. Gordon
 
Modules and packages in python
TMARAGATHAM
 
Python basics
RANAALIMAJEEDRAJPUT
 
Datatypes in python
eShikshak
 
Class and object in C++
rprajat007
 
Python - the basics
University of Technology
 
Lesson 02 python keywords and identifiers
Nilimesh Halder
 
Introduction to the basics of Python programming (part 1)
Pedro Rodrigues
 
Conditionalstatement
RaginiJain21
 
Python Tutorial Part 1
Haitham El-Ghareeb
 
Python ppt
Anush verma
 
Python tuple
Mohammed Sikander
 
structure and union
student
 
Values and Data types in python
Jothi Thilaga P
 
Oop c++class(final).ppt
Alok Kumar
 
Static Data Members and Member Functions
MOHIT AGARWAL
 
Datatype in c++ unit 3 -topic 2
MOHIT TOMAR
 
Python Functions
Mohammed Sikander
 
Python set
Mohammed Sikander
 
What is Python Lambda Function? Python Tutorial | Edureka
Edureka!
 
Python: Modules and Packages
Damian T. Gordon
 
Ad

Similar to Basic data types in python (20)

PPTX
Data Types In Python.pptx
YatharthChaudhary5
 
DOCX
unit 1.docx
ssuser2e84e4
 
PPTX
2. Values and Data types in Python.pptx
deivanayagamramachan
 
PDF
E-Notes_3720_Content_Document_20250107032323PM.pdf
aayushihirpara297
 
PPTX
Presentation on python data type
swati kushwaha
 
PDF
Datatypes in Python.pdf
king931283
 
PPTX
IOT notes,................................
taetaebts431
 
PPTX
PYTHON DATA TYPE IN PROGRAMMING LANG.pptx
urvashipundir04
 
PPTX
Python Session - 3
AnirudhaGaikwad4
 
PPTX
Python data type
nuripatidar
 
PPTX
Python
reshmaravichandran
 
PPTX
PYTHON DATA TYPE in python using v .pptx
urvashipundir04
 
PPTX
009 Data Handling class 11 -converted.pptx
adityakumar123456112
 
PPTX
009 Data Handling .pptx
ssuser6c66f3
 
PPTX
11 Unit 1 Chapter 03 Data Handling
Praveen M Jigajinni
 
PDF
4. Data Handling computer shcience pdf s
TonyTech2
 
PPTX
Python data type
Jaya Kumari
 
PPTX
Chapter 10 data handling
Praveen M Jigajinni
 
PPTX
The Datatypes Concept in Core Python.pptx
Kavitha713564
 
Data Types In Python.pptx
YatharthChaudhary5
 
unit 1.docx
ssuser2e84e4
 
2. Values and Data types in Python.pptx
deivanayagamramachan
 
E-Notes_3720_Content_Document_20250107032323PM.pdf
aayushihirpara297
 
Presentation on python data type
swati kushwaha
 
Datatypes in Python.pdf
king931283
 
IOT notes,................................
taetaebts431
 
PYTHON DATA TYPE IN PROGRAMMING LANG.pptx
urvashipundir04
 
Python Session - 3
AnirudhaGaikwad4
 
Python data type
nuripatidar
 
PYTHON DATA TYPE in python using v .pptx
urvashipundir04
 
009 Data Handling class 11 -converted.pptx
adityakumar123456112
 
009 Data Handling .pptx
ssuser6c66f3
 
11 Unit 1 Chapter 03 Data Handling
Praveen M Jigajinni
 
4. Data Handling computer shcience pdf s
TonyTech2
 
Python data type
Jaya Kumari
 
Chapter 10 data handling
Praveen M Jigajinni
 
The Datatypes Concept in Core Python.pptx
Kavitha713564
 
Ad

More from sunilchute1 (10)

PPTX
Programming construction tools
sunilchute1
 
PPTX
Introduction to data structure
sunilchute1
 
PPTX
Sorting method data structure
sunilchute1
 
PPTX
Introduction to data structure
sunilchute1
 
PPTX
Input output statement
sunilchute1
 
PPTX
Call by value and call by reference in java
sunilchute1
 
PPTX
Java method
sunilchute1
 
PPTX
Constructors in java
sunilchute1
 
PPTX
C loops
sunilchute1
 
PPT
Basic of c language
sunilchute1
 
Programming construction tools
sunilchute1
 
Introduction to data structure
sunilchute1
 
Sorting method data structure
sunilchute1
 
Introduction to data structure
sunilchute1
 
Input output statement
sunilchute1
 
Call by value and call by reference in java
sunilchute1
 
Java method
sunilchute1
 
Constructors in java
sunilchute1
 
C loops
sunilchute1
 
Basic of c language
sunilchute1
 

Recently uploaded (20)

PPTX
Understanding operators in c language.pptx
auteharshil95
 
PPTX
Odoo 18 Sales_ Managing Quotation Validity
Celine George
 
PPTX
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
PPTX
IMMUNIZATION PROGRAMME pptx
AneetaSharma15
 
PDF
The Final Stretch: How to Release a Game and Not Die in the Process.
Marta Fijak
 
PPTX
Presentation on Janskhiya sthirata kosh.
Ms Usha Vadhel
 
PPTX
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
PPTX
How to Manage Global Discount in Odoo 18 POS
Celine George
 
PDF
1.Natural-Resources-and-Their-Use.ppt pdf /8th class social science Exploring...
Sandeep Swamy
 
PDF
The Picture of Dorian Gray summary and depiction
opaliyahemel
 
PDF
High Ground Student Revision Booklet Preview
jpinnuck
 
PPTX
Open Quiz Monsoon Mind Game Prelims.pptx
Sourav Kr Podder
 
PDF
Landforms and landscapes data surprise preview
jpinnuck
 
PDF
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Sandeep Swamy
 
PDF
Module 3: Health Systems Tutorial Slides S2 2025
Jonathan Hallett
 
DOCX
UPPER GASTRO INTESTINAL DISORDER.docx
BANDITA PATRA
 
PPTX
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
Mithil Fal Desai
 
PDF
3.The-Rise-of-the-Marathas.pdfppt/pdf/8th class social science Exploring Soci...
Sandeep Swamy
 
PPTX
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 
Understanding operators in c language.pptx
auteharshil95
 
Odoo 18 Sales_ Managing Quotation Validity
Celine George
 
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
IMMUNIZATION PROGRAMME pptx
AneetaSharma15
 
The Final Stretch: How to Release a Game and Not Die in the Process.
Marta Fijak
 
Presentation on Janskhiya sthirata kosh.
Ms Usha Vadhel
 
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
How to Manage Global Discount in Odoo 18 POS
Celine George
 
1.Natural-Resources-and-Their-Use.ppt pdf /8th class social science Exploring...
Sandeep Swamy
 
The Picture of Dorian Gray summary and depiction
opaliyahemel
 
High Ground Student Revision Booklet Preview
jpinnuck
 
Open Quiz Monsoon Mind Game Prelims.pptx
Sourav Kr Podder
 
Landforms and landscapes data surprise preview
jpinnuck
 
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Sandeep Swamy
 
Module 3: Health Systems Tutorial Slides S2 2025
Jonathan Hallett
 
UPPER GASTRO INTESTINAL DISORDER.docx
BANDITA PATRA
 
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
Mithil Fal Desai
 
3.The-Rise-of-the-Marathas.pdfppt/pdf/8th class social science Exploring Soci...
Sandeep Swamy
 
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 

Basic data types in python

  • 1. BASIC DATA TYPES IN PYTHON PROF. SUNIL D. CHUTE HEAD DEPT OF COMPUTER SCIENC M.G. COLLEGE ARMORI
  • 2. BASIC DATA TYPES IN PYTHON  Data types are the classification or categorization of data items. It represents the kind of value that tells what operations can be performed on a particular data. Since everything is an object in Python programming, data types are actually classes and variables are instance (object) of these classes.
  • 3. One way to categorize these basic data types is in one of four groups:  Numeric: int, float and the less frequently encountered complex  Sequence: str (string), list and tuple  Boolean: (True or False)  Dictionary: dict(dictionary) data type, consisting of (key, value) pairs NOTE: It's important to point out that Python usually doesn't require you to specify what data type you are using and will assign a data type to your variable based on what it thinks you meant. An equally important thing to point out is that Python is a "loosely/weakly typed" programming language, meaning that a variable can change its type over the course of the program's execution, which isn't the case with "strongly typed" programming languages (such as Java or C++).
  • 5. NUMERIC DATA TYPES These data types are fairly straight-forward and represent numeric values. These can be decimal values, floating point values or even complex numbers.  Integer Data Type - int The int data type deals with integers values. This means values like 0, 1, -2 and -15, and not numbers like 0.5, 1.01, - 10.8, etc. If you give Python the following code, it will conclude that a is an integer and will assign the int data type to it: >>> x = 5 >>> type(x) <class 'int'> We could have been more specific and said something along these lines, to make sure Python understood our 5 as an integer, though, it'll automatically do this exact same thing under the hood:
  • 6. >>> x = int(5) >>> type(x) <class 'int‘> It's worth noting that Python treats any sequence of numbers (without a prefix) as a decimal number. This sequence, in fact, isn't constrained. That is to say, unlike in some other languages like Java, the value of the int doesn't have a maximum value - it's unbounded. The sys.maxsize may sound counterintuitive then, since it implies that that's the maximum value of an integer, though, it isn't. >>> x = sys.maxsize >>> x 2147483647 This appears to be a 32-bit signed binary integer value, though, let's see what happens if we assign a higher number to x: >>> x = sys.maxsize >>> x+1 2147483648
  • 7. In fact, we can even go as far as: >>> y = sys.maxsize + sys.maxsize >>> y 4294967294 The only real limit to how big an integer can be is the memory of the machine you're running Python on.  Prefixing Integers What happens when you'd like to pack a numeric value in a different form? You can prefix a sequence of numbers and tell Python to treat them in a different system. More specifically, the prefixes:  0b or 0B - Will turn your integer into Binary  0o or 0O - Will turn your integer into Octal  0x or 0X - Will turn your integer into Hexadecimal
  • 8.  # Decimal value of 5 >>> x = 5 >>> x 5  # Binary value of 1 >>> x = 0b001 >>> x 1  # Octal value of 5 >>> x = 0o5 >>> x 5  # Hexadecimal value of 10 >>> x = 0x10 >>> x 16
  • 9. FLOATING POINT DATA TYPE - FLOAT  The float type in Python designates a floating-point number. float values are specified with a decimal point. Optionally, the character e or E followed by a positive or negative integer may be appended to specify scientific notation Ex.1 >>> 4.2 4.2 >>> type(4.2) <class 'float'> Ex.2 >>> 4. 4.0 Ex.3 >>> .2 0.2 Ex.4>>> .4e7 4000000.0 >>> type(.4e7) <class 'float'> Ex.5>>> 4.2e-4
  • 10. COMPLEX NUMBERS  Complex numbers are specified as <real part>+<imaginary part>j. Ex. >>> 2+3j (2+3j) >>> type(2+3j) <class 'complex'>
  • 11. STRINGS  Strings are sequences of character data. The string type in Python is called str.  String literals may be delimited using either single or double quotes. All the characters between the opening delimiter and matching closing delimiter are part of the string: Ex.>>> print("I am a string.") I am a string. >>> type("I am a string.") <class 'str'> Ex.>>> print('I am too.') I am too. >>> type('I am too.') <class 'str'>
  • 12.  A string in Python can contain as many characters as you wish. The only limit is your machine’s memory resources. A string can also be empty: Ex. >>> '' ''  What if you want to include a quote character as part of the string itself? Your first impulse might be to try something like this: Ex.>>> print('This string contains a single quote (') character.') SyntaxError: invalid syntax Ex. >>> mystring = "This is not my first String" >>> print (mystring); This is not my first String
  • 13.  to join two or more strings. Ex.>>> print ("Hello" + "World"); HelloWorld Ex. >>> s1 = "Name Python " >>> s2 = "had been adapted " >>> s3 = "from Monty Python" >>> print (s1 + s2 + s3) Name Python had been adapted from Monty Python
  • 14.  use input() function Ex.>>> n = input("Number of times you want the text to repeat: ") Number of times you want the text to repeat: >>> print ("Text"*n); TextTextTextTextText  Check existence of a character or a sub- string in a string Ex.>>> "won" in "India won the match" True
  • 15. PYTHON LIST DATA TYPE  List is an ordered sequence of items. It is one of the most used datatype in Python and is very flexible. All the items in a list do not need to be of the same type.  Declaring a list is pretty straight forward. Items separated by commas are enclosed within brackets [ ]. Ex. a = [1, 2.2, 'python'] We can use the slicing operator [ ] to extract an item or a range of items from a list. The index starts from 0 in Python.
  • 17. PYTHON TUPLE DATA TYPE  Tuple is an ordered sequence of items same as a list. The only difference is that tuples are immutable. Tuples once created cannot be modified.  Tuples are used to write-protect data and are usually faster than lists as they cannot change dynamically.  It is defined within parentheses () where items are separated by commas. Ex. t = (5,'program', 1+3j)
  • 18.  We can use the slicing operator [] to extract items but we cannot change its value.
  • 19. PYTHON SET DATA TYPE  Set is an unordered collection of unique items. Set is defined by values separated by comma inside braces { }. Items in a set are not ordered.  A set is created by placing all the items (elements) inside curly braces {}, separated by comma, or by using the built- in set() function.  It can have any number of items and they may be of different types (integer, float, tuple, string etc.). But a set cannot have mutable
  • 22. PYTHON DICTIONARY DATA TYPE  Python dictionary is an unordered collection of items. Each item of a dictionary has a key/value pair.  It is generally used when we have a huge amount of data. Dictionaries are optimized for retrieving data. We must know the key to retrieve the value.  In Python, dictionaries are defined within braces {} with each item being a pair in the form key:value. Key and value can be of any type.