What is Python (1)
What is Python (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
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.
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)
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.
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.
The print() function can also display the values of one or more variables separated by
a comma.
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.