Numbers

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..

5 1 vote
Lesson Rating
Subscribe
Notify of
profile avatar
0 Comments
Inline Feedbacks
View all comments

Saving Progress...

Sign up for free!

Sign up for free and get instant access to this course!.

Python 3 Fundamentals

0%

0/1 Lessons

Installing Python on Windows

• 1hr 17min

0 / 4 lessons complete

Python Basics

• 28min

0 / 7 lessons complete

Python Variables

• 41min

0 / 8 lessons complete

Even more Python Variables!

• 41min

0 / 6 lessons complete

Conditional Statements

• 15min

0 / 3 lessons complete

Writing Functions

• 30min

0 / 5 lessons complete

Python Loops

• 23min

0 / 5 lessons complete

Python PIP and Modules

• 18min

0 / 4 lessons complete

RegEx

• 26min

0 / 4 lessons complete

Working with APIs

• 12min

0 / 3 lessons complete

Course Conclusion

• 2min

0 / 1 lessons complete