Python number

There are several different types of numbers in Python, including:

  1. int (short for “integer”) represents a whole number. For example: 42, -10, 0
  2. float (short for “floating point”) represents a number with a decimal point. For example: 3.14, -0.01, 0.0

Here’s a simple example of how you can use numbers in Python:

>>> # Add two numbers
>>> x = 10
>>> y = 20
>>> z = x + y
>>> print(z)
30

>>> # Multiply two numbers
>>> a = 10
>>> b = 3.14
>>> c = a * b
>>> print(c)
31.4

>>> # Divide two numbers
>>> d = 20
>>> e = 4
>>> f = d / e
>>> print(f)
5.0

>>> # Check the type of a variable
>>> print(type(f))
<class 'float'>

You can also perform more advanced operations on numbers, such as raising a number to a power or finding the remainder when one number is divided by another. For example:

>>> # Raise a number to a power
>>> g = 2
>>> h = 8
>>> i = g ** h
>>> print(i)
256

>>> # Find the remainder when one number is divided by another
>>> j = 23
>>> k = 7
>>> l = j % k
>>> print(l)
2

I hope this helps! Let me know if you have any questions.

Was this helpful?
[0]