0% found this document useful (0 votes)
1 views

What is Python (1)

The document provides an overview of Python, highlighting its characteristics as a general-purpose programming and scripting language. It discusses the differences between programming and scripting languages, outlines Python's features and advantages, and explains how to install Python on Windows. Additionally, it covers the use of the Python interpreter, IDLE, syntax for displaying output, getting user input, and writing comments in Python scripts.

Uploaded by

Mark Gil
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

What is Python (1)

The document provides an overview of Python, highlighting its characteristics as a general-purpose programming and scripting language. It discusses the differences between programming and scripting languages, outlines Python's features and advantages, and explains how to install Python on Windows. Additionally, it covers the use of the Python interpreter, IDLE, syntax for displaying output, getting user input, and writing comments in Python scripts.

Uploaded by

Mark Gil
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Integrated Prepared by:

Mark Gil D. Galisanao


Programming and
Technologies 2 ITEC 111 - LESSON 1

Date: 09/28/2024

What is Python?
is a general purpose programming language that is often applied in scripting roles.
Python is programming language as well as scripting language.
Python is also called as Interpreted language

Differences between programming and scripting language


Programming - is executed (i.e. the source is first compiled, and the result of that
compilation is expected) A "program" in general, is a sequence of instructions written so
that a computer can perform certain task.
Scripting - A "script" is code written in a scripting language. A scripting language is
nothing but a type of programming language in which we can write code to control
another software application.

Python Features:
Python is an interpreter-based language, which allows the execution of one instruction at
a time.
Extensive basic data types are supported e.g., numbers (floating point, complex, and
unlimited-length long integers), strings (both ASCII and Unicode), lists, and dictionaries.
Variables can be dynamic typed.
Supports automatic memory management.
Supports object-oriented programming concepts such as class, inheritance, objects,
module, namespace etc.
Cleaner exception handling support.
Various built-in and third-party modules, which can be imported and used independently
in the Python application.

Python Advantages
1. Python provides enhanced readability.
2. Python is free and distributed as open-source software.
3. Python is a cross-platform language.
4. Python supports multiple programming paradigms including imperative, procedural,
object-oriented, and functional programming styles.
5. A standard DB-API for database connectivity has been defined in Python.
6. Python can be integrated with other popular programming technologies like C, C++, Java,
ActiveX, and CORBA.

Install Python on Windows


To install Python on a Windows platform, you need to download the installer. A web-based
installer, executable installer and embeddable zip files are available to install Python on
Windows. Visit https://www.python.org/downloads/windows and download the installer
based on your local machine's hardware architecture.

The web-based installer needs an active internet connection. So, you can also download
the standalone executable installer. Visit https://www.python.org/downloads and click on
the Download Python 3.712.6 button as shown below. (Latest Python 3 Release - Python
3.12.6)

Python Interpreter: Shell/REPL


Python is an interpreter language. It means it executes the code line by line. Python
provides a Python Shell, which is used to execute a single Python command and display
the result.

It is also known as REPL (Read, Evaluate, Print, Loop), where it reads the command,
evaluates the command, prints the result, and loop it back to read the command
again.

To run the Python Shell, open the command prompt or power shell on Windows and
terminal window on mac, write python and press enter. A Python Prompt comprising of
three greater-than symbols >>> appears, as shown below.
Now, you can enter a single statement and get the result. For example, enter a simple
expression like 3 + 2, press enter and it will display the result in the next line, as
shown below.

Execute Python Script


As you have seen above, Python Shell executes a single statement. To execute
multiple statements, create a Python file with extension .py, and write Python scripts
(multiple statements).

For example, enter the following statement in a text editor such as Notepad.

Save it as myPythonScript.py, navigate the command prompt to the folder where you
have saved this file and execute the python myPythonScript.py command, as shown
below. It will display the result.

Thus, you can execute Python expressions and commands using Python REPL to
quickly execute Python code.

Python - IDLE
IDLE (Integrated Development and Learning Environment) is an integrated development
environment (IDE) for Python. The Python installer for Windows contains the IDLE module
by default.

IDLE can be used to execute a single statement just like Python Shell and also to create,
modify, and execute Python scripts. IDLE provides a fully-featured text editor to create
Python script that includes features like syntax highlighting, autocompletion, and smart
indent. It also has a debugger with stepping and breakpoints features.

You can execute Python statements same as in Python Shell as shown below.
To execute a Python script, create a new file by selecting File -> New File from the
menu.

Enter multiple statements and save the file with extension .py using File -> Save. For
example, save the following code as hello.py.
Now, press F5 to run the script in the editor window. The IDLE shell will show the
output.

Thus, it is easy to write, test and run Python scripts in IDLE.


Python Syntax
Display Output
The print() function in Python displays an output to a console or to the text stream file.
You can pass any type of data to the print() function to be displayed on the console.

The print() function can also display the values of one or more variables separated by
a comma.

Getting User's Input


The input() function is used to get the user's input. It reads the key strokes as a string
object which can be referred to by a variable having a suitable name.

Note that the blinking cursor waits for the user's input. The user enters his input and
then hits Enter. This will be captured as a string.

In the above example, the input() function takes the user's input from the next line,
e.g. 'Steve' in this case. input() will capture it and assign it to a name variable. The
name variable will display whatever the user has provided as the input.

The input() function has an optional string parameter that acts as a prompt for the
user.
The input() function always reads the input as a string, even if comprises of digits.

Code Comments in Python


In a Python script, the symbol # indicates the start of a comment line. It is effective
till the end of the line in the editor.

In Python, there is no provision to write multi-line comments, or a block comment.


For multi-line comments, each line should have the # symbol at the start.

NEXT LESSON: – Data Types , Values and Variables in Python

You might also like