How to start coding Python

This is a quick starter guide for beginners to write code in the Python programming language.

If you are using MacOS or Linux then Python will already be installed on your system, for Windows then a Python installer is available from the official website’s downloads page.

Create a basic script

Create a Python file to begin with the filename main.py. When creating Python files you always have them with the py extension.

You can use the following terminal command to create.

touch main.py

Open the file in any text/code editor, then add the following code.

print('Hello World!')

The print command will print out the word “Hello World!”.

To execute the file use the following command.

python3 main.py

You will see the text output after running the above command.

Inputting a value

Now replace the code with the following and save the file.

value = input("Enter text to output: ")

if not value:
    value = 'Hello World!'

print(value)

This will request you to input some text which will get assigned to the variable value.

The value variable is checked if it is empty, if it is then the default “Hello World!” text is assigned to it instead.

Execute the main.py to see the new change applied.

python3 main.py