Welcome To
Data Types


Data types in Python

The data types in python ia a type of data that can hold the variable. but in python no need to declare the data type explicitly and the python is a Dynamically typed programming language the python interpreter can understand the data type based an value and syntax. datatype is a blue print of variables.

The python having some built-in data type that is shown in the below

Data Types

Number Data types
int
float
complex
Sequence Data types
str(String)
List
Tuple
Range
mapping
Dict(dictionary)
Boolean
True
False
set Datatype

Number Data types

The number data types in a python variable can hold the numbers cannot be any string or other . and the number data types is immutable datatype once we creating a object with value we cannot be change anywhere in the python code. The Number data types is divided into Three types that is shown in the below

Int(Integer) DataTypes

The int data types is the variable can hold the Integer value cannot be other . and it is a immutable . the int datatype is allows positive and negative value the example shown in the below. int data type cannot hold the floating point value

Examples

x=10

x=-10

print(x)

Float Datatype

The float datatype in python variable can hold the fractional value , decimal value, floating value . it is also supports the negative and positive value . and it is a immutable cannot be changed

Examples

x=10.70

x=-10.70

print(x)

Complex Data types

The complex data type in a python is the variable can holds the imaginary value . mainly this data types used in data analytics. the mainly divided into two parts the first value is called real part and second is imaginary part followed by + and J symbols. the Examples in the below

Examples

x=10+20J # it is a imaginary value syntax

print (x)
10 # is a Real number
20 # is a imaginary value .
When you want to check the real and imaginary value
print(real(x))
print(imag(x))
output : 10.0
20.0

Sequence data types

The sequence data type the value can holds variable in order is calls sequence datatype and sequence data types is divided into three types that is shown in the below with examples

str(String)

The str datatype in python the variable can holds the string only cannot be integer . The string is a collection of character or single character that enclosed or surrounded by single quote('') or double quote("") or Triple Quotes (""" """). The Str datatype is immutable which means once object is created with value we cont change that value anywhere in the python program . Examples in the below

Examples

myName="Darshan"

print(myName)

Accessing string using index value

print(myName[0])

output:- darshan
d

List Datatype

The List ia a one type of ordered data type and mutable we can change easy that elements in list. the list datatype having the collection of data types in list that is shown in the below example. the list defined by [] square brackets

Example

List_Example=[10,"darshan",12.0,10+12J]

# In above Example the list having the four types of data

Accessing list value by using index value

print(List_Example[0])
print(List_Example[1])
print(List_Example[2])
print(List_Example[3])

OutPut: 10
darshan
12.0
10+12j

Tuple Datatype

THe tuple is a sequence datatype the elements is stored in the ordered but immutable once created tuple object with value we cannot change anywhere in the program. it is similar to list but it is immutable . it defined the parenthesis() inside ordered elements.

Examples

tuple_Example=(10,20,30,40)

# accessing using index value

print(tuple_Example[1])
print(tuple_Example[2])
print(tuple_Example[3])

print(tuple_Example[-1])


Range

The range datatype in the python it is also called function as well as datatype the range define the sequence numbers as shown in the below example

Example

for i in range(1,10,2) # The first number define the start loop. and second number define the stop loop and the third number define the steps like 2each number adds 2 as sequence.
print(i)
Output: 1,3,5,7,9

Set Datatype

the set datatype in python is unordered data type . and immutable once object value is created cannot be change anywhere in the program. The set is a set of values in side the curly brackets{} . and each element is separated with commas , it define the various data types but we con't access that elements by using index number we possible to access whole set by using set name .

Examples

set_Example{10,20,"darshan"}
print(set_Example)

Mapping Datatype(Dict)

The Mapping datatype in python is dictionary datatype which have inside key- value Pair form . and defined using {}. the property and value using : . Example shown in the below

Examples

dict_Example{
"name":"Darshan",
"age": 19,
"aim": "software"}

Boolean Datatype

In Boolean data type is commonly used for condition checking either True or False . Example shown in the below

Examples

Name=True
print(Name)

None datatype

The python provide the no defined variable is called null or none datatype

Example

name=none
print(name)

Type() Function

The python provides the special method to find the datatype that is type all examples shown below

Examples

x=10# int
print(type(x))
Output:- < class 'int'>

x=10.22# float
print(type(x))
Output:- < class 'float'>

x=10+20j# complex
print(type(x))
Output:- < class 'complex'>

x="Coder"# str
print(type(x))
Output:- < class 'str'>

x=[10,20,30,40]# list
print(type(x))
Output:- < class 'list'>

x=(10,"darshan",30,30.0)# tuple
print(type(x))
Output:- < class 'tuple'>

x={10,20,20.0}# set
print(type(x))
Output:- < class 'set'>

x={
"Name":"Darshan",
"age":19,
"aim": "Software"
}# Dict print(type(x))
Output:- < class 'dict'>

x=true# bool
print(type(x))
Output:- < class 'bool'>

x=none# none
print(type(x))
Output:- < class 'none'>