Hello World !
0-Basic Syntax
Link to the Google Colaboratory notebook: Basic Syntax
First program
We will try to execute the well-known Hello World program.
Interactive mode (local machine)
You can into interactive mode by using a terminal and run the command python.
Python 3.10.12 | packaged by conda-forge | (main, Jun 23 2023, 22:41:52) [Clang 15.0.7 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
The >>> denotes a Python Command Prompt where you can enter Python commands.
Let’s write print("Hello World !") and press Enter
Script mode (local machine)
Instead of writing a code line by line, we can write everything in a file and then run it line by line using command line.
Let’s create a file name test.py with the following content:
print("Hello World !") You can now execute the code using python test.py in a terminal.
Google Colaboratory
We will execute this code in a Google Colaboratory notebook.
The Google Colaboratory is accessible in the following link: Basic Syntax
Syntax
Indentation
Python programs don’t contain braces to indicate the end of a line.
Block are denotated by line indentation, and the lines that are indentated form a block of code.
if True:
print("Hello")
print("World !")
else:
print("Goodbye")Hello
World !
Comments
Comments can be used to explain the code.
These are lines than won’t be executed.
String line comments
You can comment a line using
#at the beginning of a line:It can also be place at the end of a line:
Comments can be line of codes that you just don’t want to execute for a moment.
Multilines comments
Sometimes, it can be usefull to have multiple lines with comments.
You can use
#that will be place at the beginning of each line.You can also use multiline comments.
You can add three quotes
"""at the beginning of your comments and end it with"""again.