This document provides an introduction to installing and using Python. It outlines two main ways to install Python: directly or through the Anaconda package manager. Installing Python directly is simpler but only provides access to Python packages, while Anaconda provides access to packages for multiple languages. The document then demonstrates how to write and run Python code directly in the command prompt or by writing scripts in an text editor like Notepad++. It also introduces using the IDLE IDE for writing and running Python scripts. Virtual environments for Python projects are described as well. Homework involves trying different Python IDEs to find the most suitable one.
3. TWO WAYS TO INSTALL
You can either choose to install Python directly, or through a package manager. One of the most popular
one is called Anaconda
Installing Python directly is easier, and only installs additional very lightweight IDE called IDLE. You can
write python program by either
1. Write and run it through IDLE
2. Write and run the code directly from command prompt
3. Installing other IDEs and write/run the program from there
4. Write the python code in a notepad or notepad++ and run it through command prompt
On the other hand, direct python installation only installs a package manager called pip, and you will
only have access to packages in Python language
4. TWO WAYS TO INSTALL
Installing Anaconda also installs python (if python has not been installed yet).
Installing Python directly is a little bit more complicated, and it installs a comparatively more heavy
Anaconda navigator. You can write and run python program by
1. Write and run it through IDEs which can be installed from Anaconda Navigator
2. Write and run the code directly from anaconda prompt
3. Write the python code in a notepad or notepad++ and run it through anaconda prompt
On the other hand, python installation through Anaconda installs a package manager called Conda, and
you with this you can have access to packages written not only in Python but other languages too.
6. PYTHON INSTALLATION
Go to https://www.python.org/downloads/windows/
Download the latest release of Python
Run the installer, and make sure to add python to PATH
8. CODING IN INTERACTIVE MODE
Once python is installed, you can open command prompt and type “python” (without quotation mark) to
write and run python code
If Python is already properly installed and added to the PATH, you will see something like this
Now, try to type print(‘hello world!’) and press ENTER.
Congratulations! You wrote your first program in Python!
9. RUNNING SCRIPT FROM COMMAND PROMPT
Writing codes directly through command prompt
can be quite limited
Thus, let’s try to write a script in a file. One the
(best) way to do this is by using Notepad++ which
can be downloaded from https://notepad-plus-
plus.org/downloads/
In this Notepad++, change language into Python
Now, write your hello world program (i.e.,
print(‘hello world’))
Save the file into your preferred directory.
10. RUNNING SCRIPT FROM COMMAND PROMPT
Now that you have your script saved, we can run it through command prompt
First, open your command prompt
If the file is in different drive compared to the default one (for example, my default cmd directory is C: but
I saved my python script in drive D: ), type the drive letter followed by colon “:” to change the drive
Now, change the directory to the folder where you saved the script by using cd command, for example;
11. RUNNING SCRIPT FROM COMMAND PROMPT
Now run the command python followed by the name of your scripts. Don’t forget the .py extension!
Congratulations! Now you can write any python program using notepad++ and run it using command
prompt!
12. WRITING AND EDITING SCRIPT USING IDLE IDE
Instead of using notepad++ to write script and using cmd to run it, you can use IDLE IDE which is
installed alongside python installation. Just find program called IDLE in your system and run it
You can write your script in IDLE window and save it to any directory you preferred
You can run the script by selecting RunRun Module on the menu bar
14. ANACONDA INSTALLATION
Go to https://www.anaconda.com/products/individual
Download windows Installer for the version you like (Or any release suitable to the Python version you installed,
if you already installed python separately)
Proceed with the installation with recommended settings (Note: When the dialog gave you two checkboxes, the
top one being the option to add Anaconda to PATH, follow the recommendation and check THE BOTTOM
CHECKBOX ONLY)
Once installed, there are two important applications that will be in your system.
First is called Anaconda prompt, which acts like cmd and helps you to install packages using either Conda or pip
package manager (Note that you can also install packages through Navigator, but you can only use Conda this
way)
The second is called Anaconda Navigator. When you open this Navigator, you will be shown a lot of IDEs that can
be used. Some of these IDEs may be ready to launch, some others may need to be installed
16. PYTHON ENVIRONMENT
When writing a program in python, we can create isolated environment in which we can create python project
(i.e. python program consisting of scripts and other supporting components)
This allows a structured way creating multiple projects, where the programmer may install specific sets of
packages that are really necessary for each project
Programmer may even use different python version in different environment
In cmd, a command “py -m venv env” (without quotation marks) can be executed from a directory to create
virtual environment called venv
We can enter this virtual environment by changing directory to this environment (using cd venv) and execute
“Scriptsactivate” (without quotation marks)
Now you can install packages you want for your project stored in that the folder where venv is located
In Anaconda Navigator, you can create new virtual environment easily using “Environments” button on the left
panel, and select the IDE you want run in this environment via the drop down menu above the list of IDEs
That being said, for now we will simply use the default environment (“base” or “root”)
17. IMPORTANT NOTES BEFORE WE START
Remember, just like a lot of other programming languages, Python is case sensitive!
Unlike many other programming language, indentation is very crucial in Python scripts.
When using a “paired symbols” in a line of code such as a pair of double quotes, a pair of single quotes,
parenthesis, etc. make sure that they really are a pair. For example when using parenthesis, make sure
that every opening parenthesis has exactly one closing parenthesis
A comment is a line of code that will not be evaluated by compiler/interpreter. It is useful to provide extra
information which may help to make the script more readable. In python, a comment is a line that starts
with #
It is not mandatory, but in python there are several unwritten rules about writing a script. One of them is
to write a variable with two words all in lower case separated by underscore. There are other ‘writing
style rules’, commonly referred as PEP 8 of which the complete list you can find here:
https://peps.python.org/pep-0008/
Along the journey, we will see a lot of writing styles either being mandatory or highly suggested by
Python community
18. HOMEWORK 1
2. Try Multiple IDEs for Python and choose one that suits you the best