Back to Course

Introduction to Python

0% Complete
0/0 Steps
  1. Python: Basics
    14Topics
    |
    15 Quizzes
  2. Python: Control Flow
    12Topics
    |
    12 Quizzes
  3. Python: Errors
    5Topics
    |
    5 Quizzes
Lesson 1, Topic 6
In Progress

Python: Integer and Float Numbers

Yasin Cakal 4 Oct 2021
Lesson Progress
0% Complete

Computers are capable of comprehending much more than strings of text. Python supports a limited number of numeric data types. It has numerous methods for storing numbers. Whichever one you use is determined by the purpose for which the number is being saved.

An integer, or int, is a non-negative integer. It lacks a decimal point and encompasses all counting numbers (-2, -1, 0, 1, 2, etc…), as well as their negatives and the number 0. If you were to count the number of people on a bus, athletes on a team, or keys in a keychain, you would almost certainly use an integer.

A decimal number is referred to as a floating-point number or float. It can be used to represent both fractional and precise amounts. If you measured the length of your bedroom wall, calculating the average test score of a seventh-grade class, or storing a basketball player’s field goal percentage, you would almost certainly use a float.

In a program, numbers can be assigned to variables or used directly as shown below:

integer_variable = 4
float_variable = 2.2

# This will output: 14
print(integer_variable + 10)

Above, we defined the variables an int and a float to represent an integer and a float, respectively. We printed the sum of the variables an int and an int with the value three. The number 3 is referred to here as a literal, meaning that it is the actual number 3 and not a variable with the number 3 assigned.

%d bloggers like this: