OpenViSTAI · Agents · Blockchain · Crypto
Menu

OPENVIST LEARN · FREE LESSONS

Write and run your first small Python script

Create a two-line program, run it explicitly and make one intentional change.

Lesson 8 of 10 · About 20 minutes · Beginner · English

By the end of this lesson

Distinguish writing source code from executing it and recognise a simple Python result.

Before you start

  • Lessons 4, 5 and 7; Python 3.12 available.

Three words to know

Source code
The text instructions stored in a program file.
Variable
A name referring to a value in a program.
Standard output
The normal stream where a program prints its result.

1. Write the program

Save a Python source fileVPS · Bash
cd "$HOME/openvist-learn"
cat > hello.py <<'PYTHON'
name = "OpenViST"
print(f"Hello, {name}!")
PYTHON
What you should see · example output
No output is normally printed while the file is written.

name holds a text string. The f-string inserts that value into the message; print sends the message to standard output. The quoted PYTHON marker belongs to Bash and is not part of the .py file.

2. Read, then run

Inspect the saved sourceVPS · Bash
cat hello.py
What you should see · example output
name = "OpenViST"
print(f"Hello, {name}!")
Run it with the interpreterVPS · Bash
python3 hello.py
What you should see · example output
Hello, OpenViST!

You do not need chmod +x because you explicitly ask python3 to read the file. Typing a script filename alone is a different execution method and is not needed here.

3. Make a controlled edit

Replace the practice greetingVPS · Bash
cat > hello.py <<'PYTHON'
name = "learner"
print(f"Hello, {name}!")
PYTHON
python3 hello.py
What you should see · example output
Hello, learner!

Changing the file changes the next run, not a run that has already finished. Keeping these two actions separate helps when you later update recipes: save the intended version, run it, then inspect its output.

Read an error before changing anything

  • No such file: check the folder and filename.
  • SyntaxError: inspect the line indicated by Python for missing quotes or parentheses.
  • A prompt containing >>> is Python’s interactive interpreter. Use exit() there before running the shell command python3 hello.py.

YOUR TURN

A small check before you continue

Change the greeting to your first name and predict the result before running it. What part of the first block prevents Bash from expanding its body?

Show a suggested answer

The quoted here-document marker makes the body literal. The final Python output should contain the string assigned to name.

Sources and scope

Documentation and examples reviewed 2026-10-18. Provider screens, package versions and output wording can differ. Examples show expected outcomes; they are not a claim that OpenViST connected to your server or verified your setup.

Keep learning with a real example