Monday, 16 May 2016

Learn Python the easy way - 2. Simple operations

We can use mathematical operations in Python. Enter a calculation directly into Python console, and it will display the answer.

>>>5 + 2
7

>>>6 * 4
24

>>>4 + 1 - 3
2

Note: There is a space should be there in between the operator. It should work with out operator, but it makes easy to read. (operator -> +, - , / and etc; operand -> values such as 3, 4, 7)

Floats

Floats are used in Python to represent numbers that are not integers. There is a dot would be there in float. Example 3.45, 45.4. When you divide something in Python it will give you an floating value.

>>>3 / 4
0.75

>>>8 / 2
4.0

Exponentiation

We can also manipulate exponentiation in Python. It is the raising of one number to the power of another number.

>>2 ** 3
8

These two asterisks equal to ^ (The power symbol).

Quotient and reminder

To determine the quotient

>>>50 // 3
16

To determine the remainder

>>>10 % 4
2

Example (try to solve your self)

>>>78 % (6 // 4)


1 comment:

  1. The Blog is very informative and helpful. I like this blog. Thanks for sharing.
    Python Training
    Python Course
    Python Institute

    ReplyDelete