Data Types
by
Jyostna Devi Bodapati
Python Programming Specialization
Python Programming – Data Structures
Agenda
▪ Properties of Python Data Types
▪ Python Data Types
▪ Scalar
▪ Sequence
▪ Mapping
▪ Set
Python Programming Specialization
Python Programming – Data Structures
Data Type
Python Programming Specialization
Python Programming – Data Structures
Data Type
▪ Data type determines:
▪ the type of value stored in a variable/object
▪ the operations that can be performed on the data
▪ Ex: s = “Python”
▪ The above statement indicates that s is a string, and it is not valid to perform
operations like arithmetic and bit-wise operations on the variable s
Python Programming Specialization
Python Programming – Data Structures
Data Type
▪ Data type determines:
▪ the type of value stored in a variable/object
▪ the operations that can be performed on the data
▪ Ex: a = 100
▪ The above statement indicates that a is an integer , and it is valid to perform
operations like arithmetic, relational and bit-wise operations on the variable a
Python Programming Specialization
Python Programming – Data Structures
Properties of Python Data Types
Python Programming Specialization
Python Programming – Data Structures
Python Data Types: Property1
▪ Python is a dynamically typed language
▪ Advance Declaration of variables is not required in Python
▪ Depending on the value assigned to the variables, their type is decided
▪ Examples:
▪ >>> a = 10 # int
▪ >>> b = 10.3 # float
▪ >>> c = “Python” # string
▪ >>> d = [10, 20, 30, 40] # list
Python Programming Specialization
Python Programming – Data Structures
Python Data Types: Property2
▪ Type of the variable can be changed during the execution
▪ Examples:
▪ >>> x = 5 # int
▪ >>> x = 0.3 # float
▪ >>> x = “Hello python” # string
▪ >>> x = ( 1, 2, 3, 4 ) # tuple
▪ Note: A variable can not belong to multiple data types at a time
Python Programming Specialization
Python Programming – Data Structures
Python Data Types: Property3
▪ Every data item is treated as an object in Python
▪ Data types are treated as classes
▪ Variables are the instances (objects) of the classes
▪ Example:
▪ >>> A = 100
100A
object
Variable
Instance of
Integer class
Python Programming Specialization
Python Programming – Data Structures
Python Data Types: Property4
▪ In a weakly typed language a compiler / interpreter will sometimes change the
type of a variable
▪ Ex: “Hello” + 5 is valid in weakly typed languages
▪ Such Conversions are not valid in Python
▪ Python is a strongly typed language
▪ Unexpected changes to value/variable type is not valid in Python
▪ Ex: “Hello” + 5 #invalid
Python Programming Specialization
Python Programming – Data Structures
Python Data Types: Properties
▪ Python is a dynamically typed language
▪ Data type of a Variable can be changed during execution
▪ Python Data types are classes
▪ Python is a strongly typed language
Python Programming Specialization
Python Programming – Data Structures
Getting the data type
Python Programming Specialization
Python Programming – Data Structures
Python Data Types: type()
▪ Method type() returns the type of an object
▪ Example:
▪ >>> A = 100
▪ >>> print( type ( A ) )
▪ Output: <class 'int'>
Python Programming Specialization
Python Programming – Data Structures
Python Data Types
Python Programming Specialization
Python Programming – Data Structures
Python Data Types
▪ Python supports numerous data types to support storing variety of data
Data Types
Scalar Sequence Mapping Set
Python Programming Specialization
Python Programming – Data Structures
Python Data Types
Data Types
Scalar Data
int
float
complex
boolean
Sequence Data
List
Tuple
String
Mapping Type
Dictionary
Set Type
Set
Frozen Set
Python Data types properties

Python Data types properties

  • 1.
  • 2.
    Python Programming Specialization PythonProgramming – Data Structures Agenda ▪ Properties of Python Data Types ▪ Python Data Types ▪ Scalar ▪ Sequence ▪ Mapping ▪ Set
  • 3.
    Python Programming Specialization PythonProgramming – Data Structures Data Type
  • 4.
    Python Programming Specialization PythonProgramming – Data Structures Data Type ▪ Data type determines: ▪ the type of value stored in a variable/object ▪ the operations that can be performed on the data ▪ Ex: s = “Python” ▪ The above statement indicates that s is a string, and it is not valid to perform operations like arithmetic and bit-wise operations on the variable s
  • 5.
    Python Programming Specialization PythonProgramming – Data Structures Data Type ▪ Data type determines: ▪ the type of value stored in a variable/object ▪ the operations that can be performed on the data ▪ Ex: a = 100 ▪ The above statement indicates that a is an integer , and it is valid to perform operations like arithmetic, relational and bit-wise operations on the variable a
  • 6.
    Python Programming Specialization PythonProgramming – Data Structures Properties of Python Data Types
  • 7.
    Python Programming Specialization PythonProgramming – Data Structures Python Data Types: Property1 ▪ Python is a dynamically typed language ▪ Advance Declaration of variables is not required in Python ▪ Depending on the value assigned to the variables, their type is decided ▪ Examples: ▪ >>> a = 10 # int ▪ >>> b = 10.3 # float ▪ >>> c = “Python” # string ▪ >>> d = [10, 20, 30, 40] # list
  • 8.
    Python Programming Specialization PythonProgramming – Data Structures Python Data Types: Property2 ▪ Type of the variable can be changed during the execution ▪ Examples: ▪ >>> x = 5 # int ▪ >>> x = 0.3 # float ▪ >>> x = “Hello python” # string ▪ >>> x = ( 1, 2, 3, 4 ) # tuple ▪ Note: A variable can not belong to multiple data types at a time
  • 9.
    Python Programming Specialization PythonProgramming – Data Structures Python Data Types: Property3 ▪ Every data item is treated as an object in Python ▪ Data types are treated as classes ▪ Variables are the instances (objects) of the classes ▪ Example: ▪ >>> A = 100 100A object Variable Instance of Integer class
  • 10.
    Python Programming Specialization PythonProgramming – Data Structures Python Data Types: Property4 ▪ In a weakly typed language a compiler / interpreter will sometimes change the type of a variable ▪ Ex: “Hello” + 5 is valid in weakly typed languages ▪ Such Conversions are not valid in Python ▪ Python is a strongly typed language ▪ Unexpected changes to value/variable type is not valid in Python ▪ Ex: “Hello” + 5 #invalid
  • 11.
    Python Programming Specialization PythonProgramming – Data Structures Python Data Types: Properties ▪ Python is a dynamically typed language ▪ Data type of a Variable can be changed during execution ▪ Python Data types are classes ▪ Python is a strongly typed language
  • 12.
    Python Programming Specialization PythonProgramming – Data Structures Getting the data type
  • 13.
    Python Programming Specialization PythonProgramming – Data Structures Python Data Types: type() ▪ Method type() returns the type of an object ▪ Example: ▪ >>> A = 100 ▪ >>> print( type ( A ) ) ▪ Output: <class 'int'>
  • 14.
    Python Programming Specialization PythonProgramming – Data Structures Python Data Types
  • 15.
    Python Programming Specialization PythonProgramming – Data Structures Python Data Types ▪ Python supports numerous data types to support storing variety of data Data Types Scalar Sequence Mapping Set
  • 16.
    Python Programming Specialization PythonProgramming – Data Structures Python Data Types Data Types Scalar Data int float complex boolean Sequence Data List Tuple String Mapping Type Dictionary Set Type Set Frozen Set