Module 6 Python-Getting-Started
Module 6 Python-Getting-Started
PROGRAMMING
PYTHON: GETTING STARTED
An interpreter is a kind of
program that executes other
programs. When you write a
Python program, the Python
interpreter reads your
program and carries out the
instructions it contains. In
effect, the interpreter is a
layer of software logic
between your code and the
computer hardware on your
machine.
• Linux users can also find RPM files, and Mac OS X users
can find various Mac specific installation packages.
INTERPRETER COMPILER
Scans the entire program and translates it as a
Translates program one statement at a time.
whole into machine code.
Interpreters usually take less amount of time Compilers usually take a large amount of time
to analyze the source code. However, the to analyze the source code. However, the
overall execution time is comparatively slower overall execution time is comparatively faster
than compilers. than interpreters.
Before proceeding with this chapter Python should be installed. See the
following for the installation of Python into your system:
Installing Python (click to install Python 3.11.3)
This section will guide you through a series of ways to run Python
scripts, depending on your environment, platform, needs, and skills as
a programmer.
So, the main difference between a module and a script is that modules are
meant to be imported, while scripts are made to be directly executed.
A widely used way to run Python code is through an interactive session. To start a
Python interactive session, just open a command-line or terminal and then type in
python, or python3 depending on your Python installation, and then hit Enter.
Now, you can write and run Python code as you wish, with the only
drawback being that when you close the session, your code will be
gone.
When you work interactively, every expression and statement you type
in is evaluated and executed immediately:
To exit interactive mode, you can use one of the following options:
On GNU/Linux (and other Unixes), there are several applications that give you access to the
system command-line. Some of the most popular are xterm, Gnome Terminal, and Konsole.
These are tools that run a shell or terminal like Bash, ksh, csh, and so on.
In this case, the path to these applications is much more varied and depends on the
distribution and even on the desktop environment you use. So, you’ll need to read your
system documentation.
On Mac OS X, you can access the system terminal from Applications → Utilities → Terminal.
When you try to run Python scripts, a multi-step process begins. In this process the
interpreter will:
Python code files can be created with any plain text editor. Open
any preferred text editor and write the following code:
Save the file in your working directory with the file name extension “.py”.
Python’s standard distribution includes IDLE as the default IDE, and you
can use it to write, debug, modify, and run your modules and scripts.
Advanced text editors like Sublime Text and Visual Studio Code also
allow you to run your scripts.
left side of the equal sign (=), and the object on the right can be
forms-of-assignment-statements-in-python/?ref=lbp
the objects.
implicitly.
1. Basic form:
This form is the most common form.
Output:
2. Tuple Assignment:
4. Sequence Assignment:
Any questions?
Nothing is impossible. The word itself says ‘I’m possible!'
— Audrey Hepburn