Your First Steps in Python: A Beginner to Intermediate Guide

Data Types: What Kind of Information Are We Storing?

Section 2

Variables and Operators: Storing and Manipulating Data

Your First Steps in Python: A Beginner to Intermediate GuideVariables and Operators: Storing and Manipulating Data

Welcome to the exciting world of Python! Before we start storing information, it's crucial to understand the different 'kinds' of information Python can handle. These are called data types. Think of them as containers designed for specific kinds of contents. Just like you wouldn't store water in a sieve, you want to use the right data type for the right kind of data to ensure your programs work efficiently and correctly.

Let's explore the fundamental data types you'll encounter most often in Python:

1. Integers (int)

These are whole numbers, positive or negative, without any decimal points. They are perfect for counting, indexing, and performing mathematical operations that don't require fractions.

age = 30
count = -5
year = 2023

2. Floating-Point Numbers (float)

These are numbers that have a decimal point. They are used for measurements, calculations involving fractions, and any time you need to represent a value with a fractional part.

price = 19.99
pi = 3.14159
temperature = -2.5

3. Strings (str)

Strings are sequences of characters. They are used to represent text, like names, messages, or any kind of textual data. You define strings by enclosing the characters in quotation marks (either single '...' or double "...").

name = "Alice"
message = 'Hello, Python!'
address = "123 Main St."
チャプターへ戻る