Python Topics:
▪ Basic Data Types in Python
Data Types ▪ Handling Data in Python
Data types in Data types are the classification or
categorization of data items. It
Python represents the kind of value that tells
what operations can be performed on a
particular data. Since everything is an
object in Python programming, data
types are classes and variables are
instance (object) of these classes.
Note – type() function is used to determine the type of data type.
In Python, numeric data type represent the data which has numeric
value. Numeric value can be integer, floating number or even
complex numbers. These values are defined
as int, float and complex class in Python.
Integers – This value is represented by int class. 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.
Numeric Float – This value is represented by float class. It is a real number
with floating point representation. It is specified by a decimal point.
Optionally, the character e or E followed by a positive or negative
integer may be appended to specify scientific notation.
Complex Numbers – Complex number is represented by complex
class. It is specified as (real part) + (imaginary part)j. For example –
2+3j
>>> x = 100
>>> print(type(x))
<class 'int'>
>>> x = 10.25
Example >>> print(type(x))
<class 'float'>
>>> x = 3 + 4j
>>> print(type(x))
<class 'complex'>
In Python, Strings are arrays of bytes representing
Unicode characters. A string is a collection of one or
String 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.
>>> s = "welcome to Python“
>>> print(s)
welcome to Python
>>> print(type(s))
<class 'str’>
Example >>> x = '''Welcome to Python'''
'Welcome to Python'
>>> print(x)
Welcome to Python
>>> print(type(x))
<class 'str'>
Data type with one of the two built-in
values, True or False. Boolean objects that are equal
to True are truthy (true), and those equal to False are
falsy (false). But non-Boolean objects can be evaluated
Boolean in Boolean context as well and determined to be true
or false. It is denoted by the class bool.
Note – True and False with capital ‘T’ and ‘F’ are valid
Booleans otherwise python will throw an error.
>>> x = True
>>> print(x)
True
>>> print(type(x))
Example <class 'bool'>
>>> y = False
>>> print(y)
False