Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

Python Script Basics for Beginners

This guide explains what a Python script is and how to write and run a very simple one.

Web Hosting2 min read4 steps

What is Python?

Python is a programming language. A programming language is a way to tell a computer what to do. A script is a small program saved in a text file. Python is popular because its code is easy to read. People use it for websites, tools and data work.

What you need

  • Python installed on your computer or server. Ask Hostvento support whether Python is on your hosting plan.
  • A plain text editor, such as Notepad.
  • For a server, an SSH client. SSH is a safe way to type commands on a faraway computer.

Your first script

Open your text editor and type:

name = "Sam"
print("Hello, " + name)

The first line stores the word "Sam" in a box called name. That box is called a variable. The second line prints a greeting.

Save the file as hello.py. The .py ending tells everyone it is Python.

Steps to run it

  1. Open a command line. On Windows, open Command Prompt. On a server, log in with SSH.
  2. Go to the folder that holds your file. Use the cd command, for example:
    cd myscripts
    This command moves you into the folder named myscripts.
  3. Run the script:
    python3 hello.py
    This command asks Python to read your file and do what it says. On Windows you may type python hello.py instead.
  4. Read the output. You should see Hello, Sam.

Four ideas to learn next

  • Variables hold information.
  • If statements let the script choose between actions.
  • Loops repeat an action many times.
  • Functions are small reusable blocks of code.

Good to know

Python cares about spaces at the start of a line. This is called indentation. Lines inside an if statement or loop must be pushed in by the same amount, usually four spaces. A wrong space gives an error.

Tip: Read error messages from the bottom up. The last line usually tells you what went wrong.

Quick recap

  • Python is an easy language for writing scripts.
  • Save scripts with the .py ending.
  • Run them with python3 filename.py.
  • Watch your indentation.
  • Ask Hostvento support whether Python is on your plan.