Python Numbers
As we know, programming languages have their prime things – Numbers, Data types, Strings, Variables etc, which play a major role in constructing a program.
When we say Numbers, we mean to say Python programming supports integers, floating point numbers and complex numbers. These are number-based data types that store various types of numeric values. Number objects get generated when programmers assign a value to them. For example:
Example:
#!/usr/bin/python
variable_name1 = 10
variable_name2 = 6.2
These reference to number objects can also be deleted by using del statement. The syntax for “del” statement is:
Syntax:
del variable_name[, variable_name2[….variable_name-N]
In Python the numeric variables are defined as:
All of them act as a class in Python, where integers and floating point/decimal values are separated based on the presence or absence of decimal point between the values. 6 is an integer whereas 6.2 is a floating point value.
Types of Numerical Data Types
Python provides four distinctive numerical types. These are:
Type Conversion (Casting)
Python has the capability and feature to convert within an expression containing the mixture of different types of values internally.
Example:
#!/usr/bin/python
x = 10.5
y = 5
#without type cast
print (x + y)
#after type cast
print (int(x) + y)
Output:
15.5
15
In the above example shows how float converted to integer.
Comments
Post a Comment