28/05/2023 Number, Mathmatic and Type Conversation of Python

In this article, I will show here the different ways of using Python that converts data type to another. It is so supportive of mathematics in the python programming language. A number of pythons are very important to declare data type.

## Data Type of Number

Mainly there are three kinds of numeric data type That are-

1. Integers
2. Floating Points
3. Complex numbers

Python in this number is called classes that are int, float, complex. Integers and floating points define these decimal numbers in presence or absence. It’s different by decimals points.

For example-

Integers and floating points, suppose 5 is an Integer and 5.0 is a floating-point.

When creating a number with a real part and an imaginary part that likes (a+b), where a is the real part and b is the imagery part.

Using some function that helps to know variable values and particular classes this number of python.

To know variable class just write type() function and check particular class needs to indicate isinstance() function.

x = 5

print(type(a))

print(type(5.0))

y =5+3j

print(C+3)

print(isinstance(c, complex))

Output of these code-

Here including important integers may be any kind of number but floating-point up to 15 decimals.

Our regular life is numbers we use that are called decimals. Decimal contains 1o digit number.

But when we use the decimal numbers on our computer or any devices that can’t understand decimal numbers, mainly computer programs used-

#Binary (2 digits, that 0 and 1)

#Hexadecimal(16 digit, that likes, 0,1,2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F)

#Octal contains (8 digit, 0, 1, 2, 3, 4, 5, 6, 7).

Python programming language represent this number of its prefix that likes

Binary -0B or 0b,

Octal – 0O or 0o,

Example of above number –

#Output : 107

print (0b1101011)

# Output : 253(/251+2)

print(0xFB+0B10)

# Output: 13

print(0o15)

Output of the programming-

## Type Conversation of python

Everyone is able to convert one number to another, which is called coercion. When you calculate some addition, subtraction coerces the integer to float implicitly, if one of them floats.

Example of this-

2+3.0

3.0

This result contains floating points, which is why showing 3.0 here.

Now we try to build in function these numbers like int, float, the complex between explicitly.

These all convert from the string. Like this example-

>>int(2,3)

2

>>int(-2,8)

-2

>>float(3)

3.0

>>complex(‘3+5j’)

3.5j

When you know this, you can easily convert one to another number like binary to hexadecimal or decimal to octal or convert 4 languages.

## Mathematic of python

Python language works as a math and random modules to solve different kinds of math problems like statistics, trigonometry, probability and logarithms.

Example of these mathematical function –

import math

print(math.pi)

print(math.cos(moth.pi))

print(math.exp(10))

print(math.log10(1000))

print(math.sinh(1))

print(math.factorial (6))

Output of these –

The above content helps you to clear concepts to know more about all types of numbers, mathematical sections of python and convert one number to another that really help to be an expert web developer, game development software development and more platforms.

Stay here and learn continuously to know more about python programming language.

error: Content is protected !!