You are on page 1of 18

Data Type

What is data type explain?


What is data type explain?
• Data type is an attribute associated with a
piece of data that tells a computer system
how to interpret its value. Understanding
data types ensures that data is collected in the
preferred format and the value of each
property is as expected.
Data type in python

Data Types Examples Explanation


Text - anything
Strings "Hello!", "23.34" between " "
becomes string
Integers 5364 Whole numbers
Floats 3.1415 Decimal Numbers
Truth values that
Booleans True, False
represent Yes/No
Data type in python
Data type in python
String data type
• In Python, A string is a sequence of characters enclosed within
a single quote or double quote. These characters could be
anything like letters, numbers, or special symbols enclosed
within double quotation marks. For example, "PYnative" is a
string.
• The string type in Python is represented using a str class.
• To work with text or character data in Python, we use Strings.
Once a string is created, we can do many operations on it, such
as searching inside it, creating a substring from it, and splitting
it.
• Split is the processes of taking a segment of data and dividing
the data into two or more portions
Example
• platform = "PYnative"
• print(type(platform)) # <class 'str'>
• # display string
print(platform) # 'PYnative'
Integer values
• Python uses the int data type to represent
whole integer values. For example, we can
use the int data type to store the roll number
of a student. The Integer type in Python is
represented using a int class.
• You can store positive and negative integer
numbers of any length such as 235, -758,
235689741.
Integer values Example
• # store int value
• roll_no = 33
• # display roll no
• print("Roll number is:", roll_no)
• # output 33
Hexadecimal Number System

• Hexadecimal numbers are represented by only


16 symbols. These symbols or values are 0, 1,
2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E and F.
Hexadecimal Number System Table
Decimal Numbers 4-bit Binary Number Hexadecimal Number
0 0000 0
1 0001 1
2 0010 2
3 0011 3
4 0100 4
5 0101 5
6 0110 6
7 0111 7
8 1000 8
9 1001 9
10 1010 A
11 1011 B
12 1100 C
13 1101 D
14 1110 E
15 1111 F
Octal Number
Float data type

• To represent floating-point values or decimal


values, we can use the float data type. For
example, if we want to store the salary, we
can use the float type.
• The float type in Python is represented using
a float class.
Types

• We can create a float variable using the two


ways
• Directly assigning a float value to a variable
• Using a float() class.
Using a float() class
• # store a floating-point value
• salary = 8000.456
• print("Salary is :", salary) # 8000.456
• print(type(salary)) # class 'float'
Complex data type
• A complex number is a number with a real
and an imaginary component represented
as a+bj where a and b contain integers or
floating-point values.
• Examples of complex data types are bills of
materials, word processing documents,
maps, time-series, images and video.
Bool data type
• In Python, to represent boolean values
(True and False) we use the bool data type.
Boolean values are used to evaluate the value
of the expression. For example, when we
compare two values, the expression is
evaluated, and Python returns the
boolean True or False.
Example
• x = 25
• y = 20
• z=x>y
• print(z) # True
• print(type(z)) # class 'bool'

You might also like