1. Hello, World!
When you start to learn a programming langugage, the first program you code is typically to print
Hello, world! to the terminal (or console). Below is the simplest command you can code in Python to get
Hello, world! to be printed.
Notice that this program is seemingly trivial, but a lot is going on. First, the
print() command is actually a
function. The word
'Hello, world!'. All string literals are enclosed by either a pair of single or double quotes. In this example, it is said that we are passing a string literal to the print function; the string literal is called a
parameter of or
argument to the print function.
This background information a lot already just to understand how to print something. Compared to other languages (e.g. Java), however, printing something to the terminal is very easy in Python. Quickly, we have already gotten ahead of ourselves by talking about functions, parameters, arguments and string literals while doing one the simplest thing possible in coding with Python.
When I specify string literals, do I use single or double quotes?
Single and double quotes may be used interchangeably to specify string literals in Python. When specifying string literals, be consistent; either always use single or double quotes, as best as you can, throughout your code.
1.1.1. Print your name
Try printing your name to the terminal.
1print('John Doe') 2print('Jane Smith')
1.1.2. Print a complete sentence
Try printing a complete sentence to the terminal.
1print('I am feeling fine today.') 2print('Today is very cold.') 3print('In fall, we fall back in time, in spring, we spring forward in time.')