PYTHON-PROGRAMMING-topic-1
PYTHON-PROGRAMMING-topic-1
PROGRAMMING
A BRIEF HISTORY OF PYTHON
•
10.2020 Python 3.9
The rapid growth of Python's
popularity began in 2010. Soon,
Python was competing with the most
popular languages like Java and
JavaScript.
Dynamically Typed
Python is a dynamically typed programming language. In Python, you
don't need to specify the variable time at the time of the variable declaration.
The types are specified at the runtime based on the assigned value due to its
dynamically typed feature.
Interpreter Based
Instructions in any programming languages must be translated into
machine code for the processor to execute them. Programming languages
are either compiler based, or interpreter based.
Interactive
Standard Python distribution comes with an interactive shell that works on
the principle of REPL (Read – Evaluate – Print – Loop). The shell presents a
Python prompt >>>. You can type any valid Python expression and press
Enter. Python interpreter immediately returns the response, and the prompt
comes back to read the next expression.
Multi-Paradigm
Python is a completely object-oriented language. Everything in a Python program
is an object. However, Python conveniently encapsulates its object orientation to
be used as an imperative or procedural language – such as C. Python also
provides certain functionality that resembles functional programming.
Standard Library
Even though it has a very few keywords (only Thirty-Five), Python software is
distributed with a standard library made of large number of modules and
packages. Thus, Python has out of box support for programming needs such as
serialization, data compression, internet data handling, and many more. Python
is known for its batteries included approach.
SOME OF THE PYTHON'S POPULAR MODULES ARE:
Tkinter
Tkinter is a Python binding to the Tk GUI toolkit. It is the
standard Python interface to the Tk GUI toolkit and is
Python's de facto standard GUI. Tkinter is included with
standard Linux, Microsoft Windows and macOS installs of
Python.
The name Tkinter comes from Tk interface. Tkinter was
written by Steen Lumholt and Guido van Rossum, then
later revised by Fredrik Lundh.
Math
The math module is a built-in module in Python that is used for
performing mathematical operations. This module provides
various built-in methods for performing different mathematical
tasks.
Open Source and Cross Platform
Python is a cross-platform language. Pre-compiled binaries are
available for use on various operating system platforms such
as Windows, Linux, Mac OS, Android OS. The reference
implementation of Python is called CPython and is written in C. You
can download the source code and compile it for your OS platform.
GUI Applications
Python's standard distribution has an excellent graphics library
called TKinter. It is a Python port for the vastly popular GUI toolkit
called TCL/Tk. You can build attractive user-friendly GUI applications
in Python. GUI toolkits are generally written in C/C++. Many of them
have been ported to Python. Examples
are PyQt, WxWidgets, PySimpleGUI etc.
Database Connectivity
Almost any type of database can be used as a backend with the Python
application. DB-API is a set of specifications for database driver software to let
Python communicate with a relational database. With many third-party libraries,
Python can also work with NoSQL databases such as MongoDB.
Extensible
The term extensibility implies the ability to add new features or modify existing
features. As stated earlier, CPython (which is Python's reference implementation)
is written in C. Hence one can easily write modules/libraries in C and incorporate
them in the standard library. There are other implementations of Python such as
Jython (written in Java) and IPython (written in C#). Hence, it is possible to write
and merge new functionality in these implementations with Java and C#
respectively.
Active Developer Community
As a result of Python's popularity and open-source nature, many Python
developers often interact with online forums and conferences. Python
Software Foundation also has a significant member base, involved in the
organization's mission to "Promote, Protect, and Advance the Python
Programming Language"
Dynamically Typed
Python is a dynamically typed programming language. It is unaware of the
variable’s type until the code is executed. As a result, declaring is pointless. It
saves the value in some memory location and then binds the variable name to
that memory container. And makes the container’s contents accessible via
that variable name. As a result, the data type is irrelevant. Because it will learn
the type of the value at run-time.
Disadvantages Of Python Programming
Poor Memory Efficiency
Python uses a significant amount of memory. It is one of the main
limitations of Python and that’s why some developers don’t use it. Python’s
adaptability to various types of data causes it to consume a lot of memory. If
the user wants to optimize memory usage, Python is not a good choice for
memory-intensive tasks.
Slow Speed
When it comes to speed, Python is slower than Java or C. Python is an
interpreted, dynamically typed language. Because Python is an interpreted
language, each line of code must be carefully organized and read before
execution. This takes even longer and results in a slow execution process.
Python’s dynamic structure slows things down even more because extra work
must be done while the code is executed. As a result, Python becomes a
secondary option when rapid acceleration is required.
Database Access
Python simplifies programming. However, when it interacts with the
database, it encounters several complications. When compared to well-
known technologies such as JDBC and ODBC, Python suffers from the
disadvantage of being underdeveloped and rudimentary when it comes
to interaction with the database and data access layer. As a result, Python
is less popular among large corporations that require easy interaction with
complex legacy data.
PyCharm
One of the best (and only) full-
featured, dedicated IDEs for
Python is PyCharm. Available in
both paid (Professional) and free
open-source (Community)
editions, PyCharm installs quickly
and easily on Windows, macOS,
and Linux platforms.
Spyder
Spyder is an open-source Python
IDE that’s optimized for data science
workflows. Spyder comes included
with the Anaconda package manager
distribution, so depending on your
setup, you may already have it
installed on your machine.
What’s interesting about Spyder is
that its target audience is data
scientists using Python. You’ll notice
this throughout. For example, Spyder
integrates well with common Python
data science libraries
like SciPy, NumPy, and Matplotlib.
Thonny
A more recent addition to
the Python IDE family, Thonny is
billed as an IDE for beginners.
Written and maintained by
the Institute of Computer
Science at the University of
Tartu in Estonia, Thonny is
available for all major
platforms, with installation
instructions on the site.
Python Standard and Implementations
Python is an object-oriented programming language and has evolved a lot
over the past few years and has gained tremendous popularity among
developers, students and data enthusiasts.
We can use any name to create and use all kinds of objects in python
project since it’s an object-oriented programming language.
There arises a lot of effort in deciding meaningful class names, method
names, variables, etc. even if it differs from developers to developers.
Naming conventions then become the rules of thumb for naming the
objects, class, variables or methods that we create.
General
• Avoid names that are too general or wordy. Maintain a good
balance between the two.
• Bad: user_list, dict_to_store_defns_of_a_word, swapNums,
moveInts.
• Good: user_info, word_definitions, swap_numbers,
move_integers.
• Avoid naming things like “X”, “Y” or “Z”. Capitalize all letters of
an abbreviation when using camelcase.
• Avoid names starting with digits. Combination of lowercase
letters (a to z) or uppercase letters (A to Z) or digits (0 to 9) or an
underscore (_) can be used.
Name a Package in python
•It is important to use only lowercase while naming a package in
python.
•Use an underscore to join multiple words.
•However, it is preferable to keep a short name. (Stick into one-
word name)
Module name
•Use lowercase for module names.
•Use an underscore to join multiple words to generate a
meaningful module name.
•Stick to 1-word module names.
Class name in Python
• Class name in python should follow naming scheme called
CapWords convention.
• Python has its built-in classes, however, are typically
lowercase.
• Exception classes should always end in “Error”.
Global Variables
• Global variables should be in lowercase
• Use an underscore to join words in a global variable.
Good Instance variable name
• Instance variable names should be in lowercase.
• Use an underscore to join multiple words in an instance variable.
• Non-public instance variable name should begin with a single
underscore.
• Use two consecutive underscores at the beginning of an instance
variable.
Functions
• Function names should be in lower case.
• Use an underscore to join words in function name.
Constants in Python
• Only use upper case for constant names.
• Use an underscore as a separator to join multiple words to form a long
constant name.
How Python Programs Are Executed