Numbers
Server Academy Members Only
Sorry, this lesson is only available to Server Academy members. Create a free account now to get instant access to this and more free courses. Click the Sign Up Free button below to get access to our free courses now, or sign in if you have an account.
In Python there are three types of numbers that you will encounter:
- Int (Integer): Positive or negative whole number (no decimal place).
- Float: Positive or negative number written in decimal format
- Complex: A real and imaginary number
Here are examples of what each number could look like:
x = 1 # int
y = 4.7 # float
z = 1j # complex
We could inspect the type of any variable using the type() function:
print( type(x) )
print( type(y) )
print( type(z) )
Here are some examples of how you can interact with the different types of numbers in Python:
Integer
Integer (int) numbers: These are whole numbers, such as 1, 2, or 3. You can create int variables and perform basic arithmetic operations on them, such as addition, subtraction, multiplication, and division. For example:
# Create an int variable and assign it a value
a = 10
# Perform arithmetic operations on the variable
b = a + 5
c = a - 5
d = a * 5
e = a / 5
# Print the results
print(b) # Output: 15
print(c) # Output: 5
print(d) # Output: 50
print(e) # Output: 2.0
Float
These are numbers with decimal points, such as 1.5, 2.3, or 3.14. You can create float variables and perform the same basic arithmetic operations as with ints. The main difference is that the result of these operations will also be a float. For example:
# Create a float variable and assign it a value
a = 10.5
# Perform arithmetic operations on the variable
b = a + 5
c = a - 5
d = a * 5
e = a / 5
# Print the results
print(b) # Output: 15.5
print(c) # Output: 5.5
print(d) # Output: 52.5
print(e) # Output: 2.1
Complex
These are numbers with a real and imaginary part, such as 3 + 2j or 4 - 5j. You can create complex variables and perform basic arithmetic operations on them, such as addition, subtraction, multiplication, and division. For example:
# Create a complex variable and assign it a value
a = 3 + 2j
# Perform arithmetic operations on the variable
b = a + 5
c = a - 5
d = a * 5
e = a / 5
# Print the results
print(b) # Output: (8+2j)
print(c) # Output: (-2+2j)
print(d) # Output: (15+10j)
print(e) # Output: (0.6+0.4j)
When would you use this? Unless you're dealing in heavy math, electrical engineering, or radiowaves (to name a few), you probably won't. So don't stress if you don't understand what an imaginary number is. You don't necessarily need to understand this to complete IT administrative tasks or software development.
An imaginary number is a number that cannot be represented in the real world. It is a number that exists only in the world of math. Imaginary numbers are often represented by the letter "i" in equations.
For example, the square root of -1 is an imaginary number. In math, we usually write it as "i". So, if you see an equation that has the letter "i" in it, it probably means that it involves an imaginary number.
Imaginary numbers can be difficult to understand because they don't represent anything we can see or touch in the real world. But even though they are difficult to understand, they are still very useful in math and science. For example, imaginary numbers are often used in equations to describe things like electricity, radio waves, and other types of energy.
Anyway, great job getting through all of that! See you in the next lecture!
Server Academy Members Only
Want to access this lesson? Just sign up for a free Server Academy account and you'll be on your way. Already have an account? Click the Sign Up Free button to get started..
Saving Progress...
Python 3 for Beginners
Installing Python on Windows • 1hr 17min
0 / 4 lessons complete
Section Overview
Free Preview Lesson
Text | 1 min
Downloading and Installing Python on Windows
Free Preview Lesson
Text | 8 min
Installing and configuring VS Code for Python
Free Preview Lesson
Text | 8 min
Lab: Installing Python
Devops Lab | 60
Python Basics • 28min
0 / 7 lessons complete
Section Overview
Text | 2 min
Executing Python Code
Free Preview Lesson
Text | 3 min
Python 3 Syntax
Free Preview Lesson
Text | 5 min
Help! Python Keywords
Free Preview Lesson
Text | 4 min
Printing to the console!
Text | 5 min
Python Operators
Text | 4 min
Section Review
Quiz | 5 min
Python Variables • 41min
0 / 8 lessons complete
Even more Python Variables! • 41min
0 / 6 lessons complete
Python Lists
Text | 8 min
Python Tuples
Text | 7 min
Python Sets
Text | 7 min
Frozensets
Text | 6 min
Dictionaries
Text | 8 min
Iterator and Iterable
Text | 5 min
Conditional Statements • 15min
0 / 3 lessons complete
Writing Functions • 30min
0 / 5 lessons complete
Section Overview
Text | 3 min
Defining Functions
Text | 4 min
Importing functions from another file
Text | 4 min
Assignment: Rock, paper, scissors
Text | 12 min
Assignment: Count Dictionary Words
Text | 7 min
Python Loops • 23min
0 / 5 lessons complete
Section Overview
Text | 2 min
For In Loops
Text | 5 min
While Loops
Text | 5 min
Nested Loops
Text | 3 min
Python Loops Challenge!
Text | 8 min
Python PIP and Modules • 18min
0 / 4 lessons complete
Section Overview
Text | 3 min
Installing Python PIP
Text | 4 min
Installing Modules with PIP
Text | 5 min
Importing Modules
Text | 6 min
RegEx • 26min
0 / 4 lessons complete
Section Overview
Text | 4 min
Regex 101
Text | 10 min
Importing Regex and manipulating strings
Text | 7 min
Regex Challenge!
Text | 5 min
Working with APIs • 12min
0 / 3 lessons complete
Making HTTP Requests
Text | 3 min
Working with JSON
Text | 5 min
Get your weather with the OpenWeatherMap
Text | 4 min
Course Conclusion • 2min
0 / 1 lessons complete