avatarSamer Sallam

Summary

The provided web content is an article that serves as part of a comprehensive Python programming course, focusing on the data structure of numbers in Python, including their types, creation, and functions for manipulation.

Abstract

The article titled "Python Numbers: Python Complete Course — Part 11" is a detailed guide that is part of the Python Complete Beginner to Expert Course. It introduces readers to the concept of numbers as a fundamental data structure in Python, explaining the four primary numerical data types: Boolean, Integer, Float, and Complex. The article demonstrates how to create each type of number in Python and highlights some built-in functions such as min(), max(), and round() that are useful for numerical operations. The author, Samer Sallam, provides examples and encourages readers to subscribe for more content and consider Medium membership to support writers and access unlimited stories.

Opinions

  • The author emphasizes the importance of understanding numbers as a core concept in Python programming.
  • Samer Sallam suggests that complex numbers are less commonly used in software engineering compared to other number types.
  • The article is positioned as a valuable resource for learning Python, with the author inviting readers to follow their Medium profile and subscribe for more educational content.
  • The author promotes the idea of supporting writers on Medium by signing up for a membership, which is presented as an affordable way to access a wealth of knowledge.
  • By providing a link to the course's GitHub repository, the author reinforces the practical nature of the course and encourages hands-on learning.

Python Numbers: Python Complete Course — Part 11

https://www.pexels.com/photo/calculator-and-pen-on-table-209224/

Before we start let me tell you that:

  • This article is a part of the Python Complete Beginner to Expert Course which you can find it here.
  • All resources are available in the “Resources” section below.
  • This article is also available as a YouTube video here.

Introduction

In this article, you will learn about the first available data structure in Python, numbers.

This article will cover the following outlines:

  1. What Is a Number?
  2. Number Types
  3. How to Create a Number?
  4. Some Useful Number Functions

1. What Is a Number?

The number is a single-item data structure that is used to store only one item, and this item should be a numeric value of any type of the types that are supported by Python. Next, you will learn about these types in detail.

Photo by Aykut Eke on Unsplash

2. Number Types

Python supports four different numerical data types:

  • Boolean: It could take only two values: True or False. When you define a boolean variable, you use the True keyword or the False keyword, but you have to know that behind the scene this value is one or zero where one refers to True and zero refers to False.
  • Integer: It is often called just int and it is used to store positive or negative numbers without decimal points like 3, -4, and so on.
  • Float: Float numbers represent real numbers and they are written with a decimal point dividing the integer and fractional parts and float can store positive or negative values.
  • Complex: Usually, a complex number is divided into two parts, real and imaginary. Each part of this number could be an integer or float. For example, you can write the complex number using this form a + b, where a and b could be integer or float. Most often complex numbers are used in complex algebra, not in software engineering. Therefore, you are not going to see complex numbers in future articles.
Photo by Timo Volz on Unsplash

3. How to Create a Number

You have to define a variable and assign a value to this variable.

  • Create a boolean number
number = True
print(number)
print(type(number))

Output:

True
<classbool’>

You can understand from what has been printed that the variable value is True and its data type is boolean.

  • Create an integer number
number = 4
print(number)
print(type(number))

Output:

4
<classint’>
  • Create a float number
number = 4.5
print(number)
print(type(number))

Output:

4.5
<classfloat’>
  • Create a complex number: as has been mentioned before a complex number is divided into two parts, real and imaginary. To define a complex number in Python, you should use the complex keyword and pass the real and imaginary values.

For example:

number = complex(10, 4)
print(number)
print(type(number))

Output:

(10+4j)
<classcomplex’>

Great, till now you have learned how to create the different types of numbers.

Now, let us learn about some predefined functions that are used with numbers in Python.

4. Some Useful Number Functions

  • min(): it is used to calculate the minimum number between a collection of numbers.

Syntax

min(arg1: int or float, arg2: int or float, *args: collection of int or float) -> int or float
Returns the minimum of all the arguments.

For example:

a = min(1, 2, 3, 4, -5)
print(a)

Output:

-5
  • max(): it is used to get the maximum number between a collection of numbers.

Syntax

max(arg1: int or float, arg2: int or float, *args: collection of int or float) -> int or float
Returns the maximum of all the arguments.

For example:

a = max(1, 2, 3, 4, 0, 1.5, -4)
print(a)

Output:

4 
  • round(): returns the rounded value of the passed number.

Syntax

round(number: float, digits=None) -> int

For example:

a = round(10.7)
print(a)

Output:

11

FYI, there are a lot of other functions available in Python to deal with numbers, and you can learn them in the future according to your code needs.

Now, let us summarize what we have learned in this article:

Photo by Ann H on pexels
  • Number: is a single-item data structure that you use to store numeric values.
  • Types of numbers: Boolean, Integer, Float, Complex.
  • There are some predefined functions IN Python to deal with numbers like min(), max(), round(), and many others.

P.S.: A million thanks for your time reading my story. Before you leave let me mention quickly two points:

  • First, to get my posts in your inbox directly, would you please subscribe here, and you can follow me here.
  • Second, writers made thousands of $$ on Medium. To get unlimited access to Medium stories and start earning, sign up now for Medium membership which only costs $5 per month. By signing up with this link, you can directly support me at no extra cost to you.

To get back to the previous article, you can use the following link:

Part 10:Introduction to Variables, Data Structures and Operators

To move on to the next article, you can use the following link:

Part 12:Arithmetic Operators

Resources:

Python
Programming
Python Numbers
Function
Data Type
Recommended from ReadMedium