We will now run a python script from a file.
Start your favorite programmer's text editor. This will depend on your platform:
Windows:
- pycharm (Recommended)
- Notepad++ (don't use notepad.exe)
- Sublime Text
Mac:
- pycharm (Recommended)
- Textedit (included with macOS)
- Sublime Text
Linux:
- pycharm (Recommended)
- Vscode (included with Lab environment)
- vi/vim
- nano
- Sublime Text
Create a file called helloworld.py and open it with the editor of your choice.
Type the following code into your text editor
print("Hello world!")
a = 10
b = 3.1
c = "hello world"Save your text editor code.
python3 helloworld.pyWhich should print out the following
Hello world!Note that simply typing variable names doesn't actually print anything here.
Why not?
We can explicitly print things:
print(a)
print(b)=> TRY re-running to see the results.
Try some arithmetic operations with your variables, like this:
a + b
a * b
a / b