1: Introduction and Fundamentals
1.1 What is Python and Why Learn It?
Python is a high-level, interpreted, dynamically typed, and multi-paradigm programming language. Unlike other more complex languages, Python is known for its clean and readable syntax, which makes it ideal for beginners. Its design focuses on code readability, resulting in lower maintenance and development costs.
Why choose Python?
- Simplicity and readability: Its syntax is very similar to English, allowing you to focus on programming logic rather than the complexity of the language.
- Versatility: It is used in almost every area of technology, from web development (with frameworks like Django and Flask) and data science (with libraries like Pandas and NumPy) to artificial intelligence and automation.
- Active community: There is a huge, global, and very collaborative community that produces a vast amount of resources, tutorials, and libraries, making learning and problem-solving much easier.
- Cross-platform: Python code runs on Windows, macOS, and Linux without the need for changes.
1.2 Installing Python and Setting Up Your Development Environment
To start programming, you need to have Python installed on your computer and a place to write and run your code.
Step 1: Install Python
- Go to the official Python website: python.org.
- Click on the "Downloads" section and download the latest version for your operating system (Windows, macOS, or Linux).
- Run the installer. Important! Make sure to check the box "Add Python to PATH" during the installation on Windows. This will allow you to run Python from the terminal.
Step 2: Set up your code editor
Although you can write code in any text editor, we recommend using a Code Editor or an Integrated Development Environment (IDE). These provide specialized tools such as syntax highlighting, autocompletion, and debugging.
We recommend using Visual Studio Code (VS Code). It is free, lightweight, and very popular.
- Download and install VS Code from the official website: code.visualstudio.com.
- Once installed, open VS Code and go to the "Extensions" section (you can find it on the left sidebar or by pressing
Ctrl+Shift+X
). - Search for the "Python" extension by Microsoft and install it.
Step 3: Your First Python Program
It’s time to write our first program!
- Open VS Code and create a new file called
hello.py
. -
Write the following code:
print("Hello, world!")
-
Save the file and open it in the terminal (if you are in VS Code, you can use the integrated terminal).
- Run the program with the following command:
python hello.py
If everything went well, you will see the message "Hello, world!"
printed in the terminal. Congratulations, you just ran your first script in Python!
1.3 Variables and Data Types
A variable is like a labeled box we use to store information in the computer’s memory. The information we store has a specific data type.
Basic data types
-
str
(String): Used to store text. Always enclosed in single (' '
) or double (" "
) quotes.name = "John" message = 'This is a Python course'
-
int
(Integer): Used to store whole numbers (without decimals), such as 1, 10, -50.age = 25 quantity = 100
-
float
(Floating-point number): Used to store numbers with decimals, such as 3.14, 2.5, -9.9.pi = 3.14159 price = 19.99
-
bool
(Boolean): Used to represent truth values:True
orFalse
. They are very important in programming logic.is_student = True has_license = False
Assigning and using variables
To assign a value to a variable, we use the equal sign (=
). You can use the print()
function to display the value of a variable in the terminal.
name = "Anna"
age = 30
height = 1.65
print(name)
print(age)
print(height)
In this module, you’ve taken your first steps. In the next module, we will explore the most common data structures in Python, such as lists and dictionaries, which will allow you to handle large amounts of information in an organized way. Are you ready?