Copyright (c) Hyperion Entertainment and contributors.

Difference between revisions of "AmigaOS Manual: Python Getting Started"

From AmigaOS Documentation Wiki
Jump to navigation Jump to search
(Changed title to "How to write Python programs" and added an example.)
(Added an introduction)
Line 5: Line 5:
 
= How to write Python programs =
 
= How to write Python programs =
   
== Program 1. Amiga.py ==
+
== Amiga.py ==
  +
  +
This program shows how to use [[AmigaOS_Manual:_Python_Functions#print.28.29|print()]] to display text on the screen. [[AmigaOS_Manual:_Python_Functions#print.28.29|Print()]] is a function which can print the given object to the screen or to a file. In the following example text "Amiga. The Computer For the Creative Mind." will be printed on the screen. The text in the source code is surrounded by single quotes (') but you can also use double quotes (").
  +
  +
=== Program 1. Amiga.py ===
  +
 
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
 
# A simple program
 
# A simple program
print 'Amiga. The Computer For the Creative Mind.'
+
print( 'Amiga. The Computer For the Creative Mind.' )
 
</syntaxhighlight>
 
</syntaxhighlight>
   
Enter the above program, and save it as '''PYTHON:Scripts/Amiga.py'''. To run the program, open a Shell window and type:
+
Enter the above program using your favourite text editor, and save it as '''PYTHON:Scripts/Amiga.py'''. To run the program, open a Shell window and type:
   
 
Python PYTHON:Scripts/Amiga.py
 
Python PYTHON:Scripts/Amiga.py

Revision as of 23:48, 8 January 2019

Running Python programs

Using Python interactively

How to write Python programs

Amiga.py

This program shows how to use print() to display text on the screen. Print() is a function which can print the given object to the screen or to a file. In the following example text "Amiga. The Computer For the Creative Mind." will be printed on the screen. The text in the source code is surrounded by single quotes (') but you can also use double quotes (").

Program 1. Amiga.py

# A simple program
print( 'Amiga. The Computer For the Creative Mind.' )

Enter the above program using your favourite text editor, and save it as PYTHON:Scripts/Amiga.py. To run the program, open a Shell window and type:

Python PYTHON:Scripts/Amiga.py

You should see the following text in your Shell window:

Amiga. The Computer for the Creative Mind.