Your First Steps in Python: A Beginner to Intermediate Guide

Exploring Numbers: Integers and Floating-Point Numbers

Section 5

Your First Python Program: Printing and Basic Data Types

Your First Steps in Python: A Beginner to Intermediate GuideYour First Python Program: Printing and Basic Data Types

Welcome back, aspiring Pythonista! In our last step, we printed our very first message to the screen. Now, let's dive into the fascinating world of numbers in Python. Computers are excellent at crunching numbers, and Python provides us with two primary ways to represent them: integers and floating-point numbers.

Integers, often shortened to 'int', are whole numbers, both positive and negative, without any decimal point. Think of them as counting numbers. Examples include 0, 1, -5, 42, and -1000. Python can handle integers of virtually any size, limited only by your computer's memory!

my_age = 30
number_of_students = 150
negative_score = -10

We can also perform standard arithmetic operations with integers:

sum_result = 5 + 3
difference = 10 - 4
product = 6 * 7
quotient = 20 / 4
exponent = 2 ** 3

Note that division with integers in Python 3 (which is what we're using) will always result in a floating-point number, even if the result is a whole number. We'll explore this more in the next section.

チャプターへ戻る