PYTHON PROGRAMMING PART II: PYTHON OBJECTS AND DATA STRUCTURE BASICS UNIT 2: NUMBERS
PYTHON PROGRAMMING
PART II: PYTHON OBJECTS AND DATA STRUCTURE BASICS
UNIT 2: NUMBERS
I. Types of numbers in Python
Python has plenty of types of numbers, and in this post, we will only mention about two common types: integer and floating-point numbers.
What are integers? Integers are just whole numbers. For example 2,-5,...
Floating point numbers are numbers with a decimal point or use an exponential to express. Some circumstances are 3.5, 7.8939, -4.37, 6E4
II. Basic Arithmetics
You have already known about all the basic arithmetic, but let me remind you about this knowledge.
Addition:
print(5+6)
->11
Subtraction:
print(4.7-2.1)
-> 2.6
Multiplication:
print(3*5)
->15
Division:
print(6/2)
->3
Floor Division:
print(7//4) #This will floor the answer of the division!
->1
Keep the remainder of the division:
print(3%2)
->1
Powers:
print(2**3) #It is 2^3=8!
->8
Which means you can also do root in the same way!
Python uses the mathematics priority, and you can also use parentheses to specify order!
We work with numbers every day, so I hope this post should be helpful for people who forgot some basic Mathematics!
Comments
Post a Comment