filmov
tv
python tutorial for beginners #2: Hello World!
Показать описание
python tutorial for beginners #2: Hello World!
Let’s get stuck in, and what better way than with the
programmer’s best friend, the ‘Hello World’ application!
Start by opening a terminal. Its current working directory will be your
home directory. It’s probably a good idea to make a directory for
the files we’ll be creating in this tutorial, rather than having them
loose in your home directory.
You can create a directory called Python using the command :
mkdir Python.
You’ll then want to change into that directory using the command
cd Python.
The next step is to create an empty file using the command
‘touch’ followed by the filename.
Now that we have our file set up, we can go ahead and open it up in nano, or any text editor of your choice. Gedit is a great editor with syntax highlighting support
that should be available on any distribution. You’ll be able to
install it using your package manager if you don’t have it already.
Our Hello World program is very simple, it only needs two lines.
The first line begins with a ‘shebang’ (the symbol #! – also known
as a hashbang) followed by the path to the Python interpreter.
#!/usr/bin/env python2
The program loader uses this line to work out what the rest of the
lines need to be interpreted with. If you’re running this in an IDE
like IDLE, you don’t necessarily need to do this.
The code that is actually read by the Python interpreter is only
a single line. We’re passing the value Hello World to the print
function by placing it in brackets immediately after we’ve called
the print function. Hello World is enclosed in quotation marks to
indicate that it is a literal value and should not be interpreted as
source code.
print(“Hello World”)
As expected, the print function in Python prints any
value that gets passed to it from the console.
You can save the changes you’ve just made to the file in nano
using the key combination Ctrl+O, followed by Enter. Use Ctrl+X
to exit nano.
You can run the Hello World program by prefixing
its filename with ./ – in this case you’d type:
Subscribe for more:
----------------------------------------------------------------------------
SWE.Safaa Al-Hayali - saf3al2a
Let’s get stuck in, and what better way than with the
programmer’s best friend, the ‘Hello World’ application!
Start by opening a terminal. Its current working directory will be your
home directory. It’s probably a good idea to make a directory for
the files we’ll be creating in this tutorial, rather than having them
loose in your home directory.
You can create a directory called Python using the command :
mkdir Python.
You’ll then want to change into that directory using the command
cd Python.
The next step is to create an empty file using the command
‘touch’ followed by the filename.
Now that we have our file set up, we can go ahead and open it up in nano, or any text editor of your choice. Gedit is a great editor with syntax highlighting support
that should be available on any distribution. You’ll be able to
install it using your package manager if you don’t have it already.
Our Hello World program is very simple, it only needs two lines.
The first line begins with a ‘shebang’ (the symbol #! – also known
as a hashbang) followed by the path to the Python interpreter.
#!/usr/bin/env python2
The program loader uses this line to work out what the rest of the
lines need to be interpreted with. If you’re running this in an IDE
like IDLE, you don’t necessarily need to do this.
The code that is actually read by the Python interpreter is only
a single line. We’re passing the value Hello World to the print
function by placing it in brackets immediately after we’ve called
the print function. Hello World is enclosed in quotation marks to
indicate that it is a literal value and should not be interpreted as
source code.
print(“Hello World”)
As expected, the print function in Python prints any
value that gets passed to it from the console.
You can save the changes you’ve just made to the file in nano
using the key combination Ctrl+O, followed by Enter. Use Ctrl+X
to exit nano.
You can run the Hello World program by prefixing
its filename with ./ – in this case you’d type:
Subscribe for more:
----------------------------------------------------------------------------
SWE.Safaa Al-Hayali - saf3al2a