Data Types in python:

Data types are the classification or categorization of data items. It 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.

The variable in Python is used to store values, and they can hold different values. Each variable in Python has its own datatype. Since Python is a dynamically typed language (The language in which we don’t need to pre-define the data-type of the variables), Hence we don’t need to define the data-type of the variables which we are declaring in our Python program.

Python interpreter implicitly binds the value which variable stores with its data type automatically.

The type () functionPython also enables us to check the datatype of the variables through which we can know which data-type value the variable is holding in the program. We need to use the type () function inside.

Python to check the datatype of the variable. When we run the type () function, it will return us the datatype of the variable we wrote inside the function.

 Data Types in Python:

  1. 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.

Here x is assigned to value 2, Y is assigned to value 3 and z = x+ y, which is printing the value 5 in z.

In Line 3 we are checking the type of z variable, as the output prints it as Integer

2. 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.

In R Programming we call this as Float or Double

Here x is assigned to value 10.5, Y is assigned to value 5.0 and z = x+ y, which is printing the value 15.5 in z.

In Line 6 we are checking the type of z variable, as the output prints it as Float.

3. Strings:

In Python, Strings are arrays of bytes representing Unicode characters. 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.

Creating String

Strings in Python can be created using single quotes or double quotes or even triple quotes.

4. Boolean / Logical Data types:

Boolean Data type is one of the built-in data types provided by Python, which are defined by the True or False keywords. Generally, it is used to represent the truth values of the expressions. The output <class ‘bool’> indicates the variable is a Boolean data type.

Here X value is 10, y value is 5 and z = x > y which is True, The output return True and Type of data type returned is bool.

Note: declaring a Boolean value to a Variable should be declared as True or False

True – First letter T should be Uppercase, and rest should be lower case

False- First letter should be Uppercase, and rest should be lower case.

Example:

So far, we have performed some Arithmetic Operation, Boolean operations, Now let’s work on more Mathematical Operations like square root, Round

To use those Mathematical Functions, we should Import package called math.

Here import math package imports all the mathematical operations.

In Line 23 I assigned a value 144 to variable A, and calculating the square root of 144, which is 12.0.

Using round function iam getting the rounded value.

Let’s Look at Strings concatenating/ Appending:

Here Variable str1 = Hello and Variable str2 = Mounika

Iam combining both string with space in line no 32 and the output is printed as Hello Mounika

Boolean Operators and its Operations:

Operators in Python at a glance: