Data types in Python

Data type

Data type define the type of the data stored in the variable. For example the data data of person to be stored in a class we use number data type to store the age and the string data type to store the name of the person and so on.

Text data type                 : String
Numeric data types        : int, float, complex
sequence data types      : list, tuple, range
Mapping data types        : dictionary
Boolean data type           : bool

String

String is a sequence of characters enclosed under single or double quotes. String is the built-in data type to represent textual data in Python.

name='Murthy'

Integer

Integers are the combination of both positive and negative integers including zero without including fractional part.

age=25

Floating point numbers

Float numbers are integers with decimal part including positive, negative and zero.

Salary=45000.00

Complex

Complex data type represent the  complex numbers. The complex numbers are represented in the form of a+bj and in that a is Real part and b is an imaginary part and j represents the square root of -1.

a=12+2j

List

List a sequential data type where the elements are arranged in the form of comma separated values between the square brackets. The list can contain heterogenous elements. List is a mutable data structure [].The List representation is.

l=[1,2,3,4,5]

Tuple

Tuple is similar to list but Tuple is an immutable data structure. That means the values can not be modified once created. The values are in between the parenthesis (). Tuple representation is.

tup=(10,23,16,18)

Range

The Range is a built-in function in Python it is used to iterate over the  sequence of numbers.

range(begin, end, step)

The range produces the numbers from begin to the end-1 by incrementing the step value. If we did not specify the step value by default the step value is +1.

r=range(1,11,1)

Dictionary

Dictionary is a data structure in which the values are stored in the form of key value pair. Each key is separated by a colon and key value pair is separated by comma. The key value should be unique. The dictionary is enclosed in curly brackets. The dictionary representation is :

dict ={'name': 'Murthy', 'age':25, 'salary': 45000.00}

Bool

Bool data type is used to represent the Boolean values 'True' or 'False' . Boolean values are used in the decision making statements and the logical statements to check the state either True or False.

s= True

More

More

MFCS
COA
PL-CG
DBMS
OPERATING SYSTEM
SOFTWARE ENG
DSA
TOC-CD
ARTIFICIAL INT

More

More

More

More
Top