Wie ist ein Python-Programm aufgebaut?
How is a Python program structured?
To create an executable Python program (Python script), a file ending with the file extension ".py" is required. Depending on the operating system, a suitable Python editor is required. The test code - e.g. print("Hello, World!") - can be used as a test for an executable Python program. A DOS console is required to start the Python program. This can be called up under Windows by clicking on the start button and typing ".cmd". Simply accept the suggested DOS console and start it. In the DOS console, type "python" and start the previously saved Python program by entering the path and file name. When the program is executed, the console will now display "Hello world".
Python comments in programs can be used for different purposes. Three typical Python comment variants:
- Explanatory comments within the code
- Better readability of the code
- for testing code (to prevent the execution of commented-out program parts)
Python programmers use these so that the next Python programmer can better understand the Python code. In this way, Python projects or a "Python job" can be better documented. A Python comment starts with a hash. Everything after the double cross "#" is ignored by Python. This allows comments to be placed before or after commands. If comments are to be made over several lines, this is done using 3 quotation marks (double quotation marks) at the beginning and end of the commented lines. People can train to become Python programmers through specific courses.