Python hello-world.py Make a Python File Executable To run the program without making it executable, navigate to the location where you saved your file, and enter this at the command prompt: You can write the program in any text editor such as Notepad or Notepad++, just be sure to save the file with a “.py” extension. To begin, open the Nano text editor and create a new file named hello-world.py by entering this at the command prompt:Įnter this code into Nano, then press Ctrl-X and Y to exit and save the file: #!/usr/bin/pythonĪll Python program files will need to be saved with a “.py” extension. To demonstrate creating and executing a Python program, we’ll make a simple “hello world” program. To access the Python REPL (where you can enter Python commands just like the command line) enter python or python3 depending on which version you want to use:Įnter Ctrl-D to exit the REPL. Python 2 and Python 3 come pre-installed on Raspbian operating systems, but to install Python on another Linux OS or to update it, simply run one of these commands at the command prompt: We’ll only cover the basics of writing and executing a Python program here, but a great tutorial covering everything a programmer needs to know about Python is the book Learning Python 5th Ed. Python is generally slower at computations than C, but its ease of use makes Python an ideal language for prototyping programs and designing applications that aren’t computationally intensive. Many (but not all) of the things you can do in C can be done in Python. There are libraries for everything you can think of – game programming, rendering graphics, GUI interfaces, web frameworks, and scientific computing. Python also has a large collection of libraries, which speeds up the development process. For example, you can use Python to program things like: However, there are more useful things you can do with Python. It can be used just like a command line with IDLE, Python’s REPL (read, eval, print, loop) function. Like shell scripts, Python can automate tasks like batch renaming and moving large amounts of files. BONUS: Download the Raspberry Pi programming cheat sheet – a one page PDF guide with instructions on how to create and execute C programs, Python programs, and Shell scripts.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |