First program in Python

 General audience classification icon  General audience classification icon
Programming in Python is quite easy. In case you're using a Raspberry Pi with Python installed, once you access the console, you can run the following code:

print("Hello IoT")

You can store a program in a text file (usually with an extension .py) or interactively type it inline in Python's console.
Assuming your file is stored in the file named helloworld.py that contains the code above, an execution and its result are presented on the screen as in figure 1.

 Hello World in Python
Figure 1: Hello World in Python

Python has an interactive console that lets one type the code in. To exit back to the command line, it is necessary to execute the quit() function (figure 2).

 Interactive Python console
Figure 2: Interactive Python console

An IDE makes programming in Python more comfortable than using a command line. There are many solutions, such as Visual Studio Code + plugins, but perhaps the easiest to use is Thonny. A sample video guide on installing and writing the first program is available on YouTube [1].

en/iot-open/getting_familiar_with_your_hardware_rtu_itmo_sut/raspberrypi_rpi/building_your_first_project_python.txt · Last modified: 2024/05/24 09:53 by pczekalski
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0