05python Lecture 05 Data Types in Python
05python Lecture 05 Data Types in Python
• Variables can hold some value, and every value has a data-type.
• Python is dynamically typed language (We don’t need to define the
data-type for the variable, Interpreter implicitly gives the datatype to
the variable based on the value).
Age=18
Python interpreter will automatically interpret variables age as an
integer type.
Standard built-in Data-types in Python
Following are the standard datatypes in Python language:
1. Numeric
a. int:
b. Float:
c. Complex:
2. Boolean (values are true or false)
3. Sequence Type:
a. String
b. List (Mutable)
c. Tuple (Immutable)
4. Set
5. Dictionary
Standard built-in Data-types in Python
Following are the standard datatypes in Python language:
1. Numeric
a. int: (Integer) for storing the integer values.
It contains positive or negative whole numbers (without fraction or decimal).
In Python there is no limit to how long an integer value can be.
Standard built-in Data-types in Python
1. Numeric
a. int: (Integer)
In Python there is no limit to how long an integer value can be.
Standard built-in Data-types in Python
Following are the standard datatypes in Python language:
1. Numeric
b. float:
For storing the decimal numeric values
Standard built-in Data-types in Python
Following are the standard datatypes in Python language:
1. Numeric
b. Complex:
For storing the complex numbers
Complex number is represented by complex class.
It is specified as (real part) + (imaginary part)j.
For example: 2+3j
Standard built-in Data-types in Python
Following are the standard datatypes in Python language:
2. Boolean
Boolean datatypes take one of the two values: True or False.
Standard built-in Data-types in Python
2. Boolean
Human=false
print(Human) //Output?
type(true)
Standard built-in Data-types in Python
Following are the standard datatypes in Python language:
3. Sequence data-types
In Python, sequence is the ordered collection of values of similar or different
data types.
Sequences allows to store multiple values in an organized and efficient
fashion.
a. String:
A string is a collection of one or more characters put in a single quote, double-quote or
triple quote.
In python there is no character data type, a character is a string of length one. It is
represented by str class.
Standard built-in Data-types in Python
a. String:
A string is a collection of one or more characters put in a single quote, double-quote or
triple quote.
In python there is no character data type, a character is a string of length one. It is
represented by str class.
Standard built-in Data-types in Python
How to store the following strings in a variable
Vivek
Aman
Shivam
Standard built-in Data-types in Python
Accessing the elements of a String:
city=“NIT Srinagar”
print(city[0])
print(city[30])
Standard built-in Data-types in Python
3. Sequence data-types
b. List:
Lists are just like the arrays, declared in other languages which is a ordered collection of
data.
It is very flexible as the items in a list do not need to be of the same type.
Standard built-in Data-types in Python
4. SET
Set is also the collection of values but has no duplicate elements
S= { 1, 2, 3}
S2={ 1, 2.3, ‘cse’ }
S3= { 1, 1, 2 }
print(S3) //What will be the output