Introduction to Python

Daniel Sarney
Python For Beginners

Welcome to Python for Beginners! If you're completely new to programming or looking to learn your first language, you've made an excellent choice. Python is widely regarded as one of the best programming languages for beginners, and in this course, I'll guide you through everything you need to know to become proficient in Python.

Python has become one of the most popular programming languages in the world, and for good reason. It's used by major companies like Google, Netflix, Instagram, and Spotify. Whether you want to build web applications, analyze data, create machine learning models, or automate tasks, Python is an incredibly versatile tool that will serve you well throughout your programming journey.

What You'll Learn

  • What Python is and why it's perfect for beginners
  • How to install Python on your computer
  • How to write and run your first Python program
  • Understanding Python's simple and readable syntax
  • Basic concepts that form the foundation of programming

What is Python?

Python is a high-level, interpreted programming language created by Guido van Rossum and first released in 1991. When I say "high-level," I mean that Python is designed to be closer to human language than machine language, making it much easier to read and write than lower-level languages like C or Assembly.

The term "interpreted" means that Python code doesn't need to be compiled before running. You write your code, and Python executes it directly. This makes the development process faster and more beginner-friendly because you can see the results of your code immediately without dealing with complex compilation steps.

Here's what makes Python particularly great for beginners:

Readable Syntax: Python code reads almost like English. For example, to check if a number is greater than 10, you simply write if number > 10:, which is intuitive and easy to understand.

Versatile: Python can be used for web development, data science, artificial intelligence, automation, game development, and much more. Learning Python opens doors to many different career paths.

Large Community: With millions of Python developers worldwide, you'll find extensive documentation, tutorials, and help whenever you need it.

Extensive Libraries: Python comes with a vast standard library and thousands of third-party packages that make complex tasks simple.

Installing Python

Before we can write any Python code, you need to have Python installed on your computer. The installation process varies slightly depending on your operating system.

Windows Installation

  1. Visit the official Python website at python.org/downloads
  2. Download the latest Python 3.x version (Python 3.11 or newer is recommended)
  3. Run the installer executable
  4. Important: Check the box that says "Add Python to PATH" - this is crucial!
  5. Click "Install Now" and wait for the installation to complete

The "Add Python to PATH" option ensures that you can run Python from the command line from any directory on your computer.

macOS Installation

macOS typically comes with Python 2.7 pre-installed, but we need Python 3:

  1. Visit python.org/downloads
  2. Download the latest Python 3.x version for macOS
  3. Run the installer package
  4. Follow the installation wizard

Alternatively, if you have Homebrew installed, you can use:

brew install python3

Linux Installation

Most Linux distributions come with Python 3 pre-installed. To check if you have Python 3:

python3 --version

If Python 3 isn't installed, use your package manager:

# Ubuntu/Debian
sudo apt-get update
sudo apt-get install python3

# Fedora
sudo dnf install python3

Verifying Your Installation

Once Python is installed, let's verify it's working correctly. Open your terminal (Command Prompt on Windows, Terminal on macOS/Linux) and type:

python --version

or on some systems:

python3 --version

You should see something like Python 3.11.5 or similar. This confirms Python is installed and accessible from your command line.

Your First Python Program

Now that Python is installed, let's write your first program! This is a tradition in programming - every programmer's first program is typically "Hello, World!"

Open a text editor. You can use:

  • Windows: Notepad, or better yet, Notepad++
  • macOS: TextEdit (make sure to use plain text mode)
  • Linux: gedit, nano, or vim
  • Better options: VS Code, PyCharm, or any code editor

Create a new file and type the following:

print("Hello, World!")

Save this file as hello.py. The .py extension tells your computer this is a Python file.

Now, open your terminal, navigate to the directory where you saved the file, and run:

python hello.py

or on some systems:

python3 hello.py

You should see Hello, World! printed to your screen. Congratulations - you've just written and executed your first Python program!

Understanding Your First Program

Let's break down what just happened:

print("Hello, World!")
  • print is a built-in Python function that displays text on the screen
  • The parentheses () contain the arguments we're passing to the function
  • "Hello, World!" is a string - text enclosed in quotation marks
  • The entire line is a statement that tells Python to display the text

This simple example demonstrates Python's readability. Even without any programming experience, you can probably guess what this code does!

Python's Interactive Mode

Python also has an interactive mode, which is perfect for experimenting and learning. To start it, simply type python or python3 in your terminal:

python

You'll see a prompt that looks like >>>. This is Python's interactive shell, also called the REPL (Read-Eval-Print Loop). You can type Python code directly here and see the results immediately:

>>> print("Hello from interactive mode!")
Hello from interactive mode!
>>> 2 + 2
4
>>> name = "Python"
>>> print(f"Learning {name} is fun!")
Learning Python is fun!

Interactive mode is excellent for testing small pieces of code and experimenting with Python's features. To exit interactive mode, type exit() or press Ctrl+D (Linux/macOS) or Ctrl+Z (Windows).

Why Python is Great for Learning

As someone who has taught programming to many beginners, I've found that Python's design philosophy makes it ideal for learning. Python follows the principle that "code is read more often than it's written," which means the language prioritizes clarity and readability.

For example, compare how you'd write a loop in Python versus other languages:

Python:

for number in range(1, 6):
    print(number)

Other languages might require:

  • Variable declarations
  • Semicolons
  • Curly braces
  • More complex syntax

Python's simplicity means you can focus on learning programming concepts rather than fighting with syntax.

Try It Yourself

Now it's your turn to practice! Try these exercises:

  1. Modify the Hello World program: Change the message to say "Hello, [Your Name]!" and run it again.

  2. Use interactive mode: Open Python's interactive mode and try:
    a. Printing different messages
    b. Doing simple math: 5 + 3, 10 * 2, 100 / 4
    c. Creating a variable: my_name = "Your Name" then print(my_name)

  3. Create a new program: Create a file called greeting.py that prints a personalized greeting using your name.

These simple exercises will help you get comfortable with running Python code and understanding the basics.

Summary

In this first lesson, you've taken your first steps into the world of Python programming. You've learned what Python is, why it's an excellent choice for beginners, how to install it on your computer, and how to write and run your first program. You've also explored Python's interactive mode, which will be a valuable tool as you continue learning.

Remember, every expert programmer started exactly where you are now. The key to learning programming is consistent practice and not being afraid to experiment. Python's forgiving nature and clear error messages make it the perfect language for learning through trial and error.

What's Next?

In the next lesson, we'll dive into Python's fundamental building blocks: variables and data types. You'll learn how to store information in your programs, work with different types of data (text, numbers, and more), and understand how Python handles different kinds of information. This foundation will be essential for everything else you'll learn in this course.

Video Tutorial Coming Soon

The video tutorial for this lesson will be available soon. Check back later!

Continue Learning

18 lessons
Python Intermediate

Start your learning journey with Python Intermediate. This course includes comprehensive lessons covering everything you need to know.