0% found this document useful (0 votes)
14 views

02 - Numbers, Operators - Math

This document introduces numeric data types in Python including integers, floats, and complex numbers. It describes common arithmetic operators like addition, subtraction, multiplication, and division. It also covers floor division, modulus, exponentiation, and square root functions. The document concludes by explaining how to add comments to Python code using the # symbol to document thoughts and logic for other programmers.

Uploaded by

Emmanuel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

02 - Numbers, Operators - Math

This document introduces numeric data types in Python including integers, floats, and complex numbers. It describes common arithmetic operators like addition, subtraction, multiplication, and division. It also covers floor division, modulus, exponentiation, and square root functions. The document concludes by explaining how to add comments to Python code using the # symbol to document thoughts and logic for other programmers.

Uploaded by

Emmanuel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Numbers, Operators & Math

Introduction & Objectives


● Understand the concept of numbers in python
● Understand how to work with basic arithmetic operators
● Understand how to use basic math functions
● Understand how to add comments to your codes
Numbers in Python
Numbers in python
Python has three built-in numeric data types: integers, floating-point numbers, and complex numbers.

1. An integer is a whole number with no decimal places. E.g 30, 2, -15, 7, -10 etc.

The name for the integer data type is int.

1. A floating-point number, or float for short, is a number with a decimal place. E.g 7.2, -1.2, 10.0 etc.The name
of the floating-point data type is float.
2. Complex numbers

NB: Using the type( ) function we can know the type of the numeric data
Arithmetic operators in Python
Arithmetic operators in python
Operators Meaning uses

+ Addition a + b; 3 + 4 = 7

- Subtraction a - b; 9 - 4 = 5

* Multiplication a * b; 3 * 5 = 15

** Exponential a ** b; 2 ** 2 = 4

/ Division a / b; 8 / 4 = 2.0

// Floor division a // b; 5 // 2 = 2

% Modulus a % b; 5 % 2 = 1

math.sqrt Square root math.sqrt(4) = 2


Comments
Comments
Comments in Python is the inclusion of short descriptions along with the code to increase its readability. A
developer uses them to write his or her thought process while writing the code. It explains the basic logic behind
why a particular line of code was written. They are just meant for the coders themselves or other developers to
understand a piece of code, especially since the Python interpreter completely ignores comments in Python.
Importance of commenting in python

● Makes the code easily understandable by other programmers


● The code becomes self-explanatory
● Helps remember why we used a specific command, method, or function in the code

Comments in python in done using the hashtag (#); everything after the hashtag is completely ignored by python
interpreter

x = 5 # x is the variable containing 5

You might also like