Clear, practical technology insights BSOD Code Lookup · Windows Error Code Lookup · Wi-Fi Troubleshooting · PC Troubleshooting Checklist

How to Write a Basic Python Program

Learn how to write a basic python program with clear steps, practical context, and useful troubleshooting guidance.

Table of Contents

This updated guide examines How to Write a Basic Python Program and organizes the essential facts, background, and practical takeaways in clear American English.

Part 1

Environment Set Up

Install the Dependencies

  1. How to Write a Basic Python Program — contextual image 1 Open the Terminal. On Linux, you can press the Alt button to open a search bar. Type "terminal" and click on Terminal.
  2. How to Write a Basic Python Program — contextual image 2 Know the commands. Terminal commands are shown in this document as:
    • command-options filename.ext
    • sudo apt-get install build-essential
      • The "sudo" command gives permission to the terminal to modify your computer. This is necessary to install any program. You will be required to enter your password.
    • The "apt-get install" command tells the computer to install the package "build-essential" which is required to install Python.
    • sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
    • These are programs that Python uses to run correctly. They are also known as 'dependencies'.

Download and Extract Python

  1. How to Write a Basic Python Program — contextual image 3 Download the latest version of Python from the Internet. Use the following command:
    • cd~/Downloads/
    • The "cd" command changes to the correct working directory so the computer can find and put programs in the right place.
    • wget http://python.org/ftp/python/2.7.5/Python-2.7.5.tgz
  2. How to Write a Basic Python Program — contextual image 4 Decompress the Python file using the following command:
    • tar -xvf Python-2.7.5.tgz
    • cdPython-2.7.5
    • Once again, we need to change the working directory. This time, we change to the newly created Python directory.

Install Python

  1. How to Write a Basic Python Program — contextual image 5 Use the. /configure command checks your computer to ensure you have all the necessary components to install Python. It will alert you of any critical errors.
    • ./configure
  2. How to Write a Basic Python Program — contextual image 6 Use the make command. It compiles the source code and creates the executables.
    • make
  3. How to Write a Basic Python Program — contextual image 7 Move the applications and libraries. With the following command, all of the applications and libraries associated with Python are moved into the correct places on your computer.
    • sudo make install

Part 2

Use Python

Write the Script

  1. How to Write a Basic Python Program — contextual image 8 Open a text editor.
    • Any text editor that can save files with a ".py" extension will do. Ubuntu 12.04 or greater is packaged with the Gedit editor.
  2. How to Write a Basic Python Program — contextual image 9 Type
    print'Hello, World!'
    • In Python, whatever is enclosed in quotes after the word print will be printed out to the screen.
  3. How to Write a Basic Python Program — contextual image 10 Save the file as "hello_world.py.
    • Be careful that the file is not saved as "hello_world.py.txt".

Run the Script

  1. How to Write a Basic Python Program — contextual image 11 Open the Terminal again.
  2. How to Write a Basic Python Program — contextual image 12 Navigate to the directory where "hello_world.py" is located.
    • Remember to use the "cd" command to change directories.
    • If you need a list of all subdirectories at your current location, use the "ls" command. "ls" stands for "list subdirectories".
  3. How to Write a Basic Python Program — contextual image 13 Run the script:
    • python hello_world.py

FAQ

What is How to Write a Basic Python Program about?

It provides a structured overview of python, explains the main context, and highlights practical takeaways for readers.

Why does this topic matter?

Understanding the main concepts helps readers evaluate the issue, avoid common mistakes, and make better-informed decisions.

How should readers use this information?

Use the guidance as a practical starting point, confirm details that may have changed, and follow current product, safety, or security recommendations.

Discussion

Reader Comments 0

Sign in with email or Google to join the discussion.