Python
Python
INTRODUCTION TO PYTHON
Web Development
Software Development
Game Development
AI & ML
Data Analytics
This list can go on as we go but why python is so much popular let’s see it in the next
topic.
You guys might have a question in mind that, why python? why not another
programming language?
So let me explain:
for eg, Javascript is the most popular language amongst web developers as it gives the
developer
the power to handle applications via different frameworks like react, vue, angular which are
used
to build beautiful User Interfaces. Similarly, they have pros and cons at the same time. so if
we
consider python it is general-purpose which means it is widely used in every domain the
reason
is it’s very simple to understand, scalable because of which the speed of development is so
fast.
Now you get the idea why besides learning python it doesn’t require any programming
background so that’s why it’s popular amongst developers as well. Python has simpler syntax
similar to the English language and also the syntax allows developers to write programs with
fewer lines of code. Since it is open-source there are many libraries available that make
developers’ jobs easy ultimately results in high productivity. They can easily focus on
business
logic and Its demanding skills in the digital era where information is available in large data
sets.
Now in the era of the digital world, there is a lot of information available on the internet
that might confuse us believe me. What we can do is follow the documentation which is a
good
start point. Once we are familiar with concepts or terminology we can dive deeper into this.
Course: https://www.udemy.com/course/python-the-complete-python-developer-course/
YouTube: https://www.youtube.com/watch?v=_uQrJ0TkZlc
CODEACADEMY:
https://www.codecademy.com/catalog/language/python
I hope now you guys are excited to get started right so you might be wondering where we can
start coding right so there are a lot of options available in markets. we can use any IDE we
are
comfortable with but for those who are new to the programming world I am listing some of
2) PyCharm: https://www.jetbrains.com/pycharm/
3) Spyder: https://www.spyder-ide.org/
4) Atom: https://atom.io/
REAL-WORLD EXAMPLES:
1) NASA (National Aeronautics and Space Agency): One of Nasa’s Shuttle Support
“Python allows us to tackle the complexity of programs like the WAS without getting bogged
Nasa also published a website (https://code.nasa.gov/) where there are 400 open source
projects
2) NETFLIX: There are various projects in Netflix which use python as follow:
Chaos Gorilla
Security Monkey
Chronos
Amongst all projects, Regional failover is the project they have as the system decreases
outage
time from 45 minutes to 7 minutes with no additional cost.
3) INSTAGRAM: Instagram also uses python extensively. They have built a photo-sharing
social platform using Django which is a web framework for python. Also, they are able to
1) WEB DEVELOPMENT: Python offers different frameworks for web development like
Django, Pyramid, Flask. This framework is known for security, flexibility, scalability.
2) GAME DEVELOPMENT: PySoy and PyGame are two python libraries that are used for
game development
4) DESKTOP GUI: Desktop GUI offers many toolkits and frameworks using which we can
build desktop applications.PyQt, PyGtk, PyGUI are some of the GUI frameworks.
The last but most important thing is how you get better at what programming you choose
is practice practice practice. Practical knowledge only acquired by playing with things so you
will get more exposure to real-world scenarios. Consistency is more important than anything
because if you practice it for some days and then you did nothing then when you start again it
will be difficult to practice consistently. So I request you guys to learn by doing projects so it
will help you understand how things get done and important thing is to have fun at the same
time.
“Beginning is the end and end is the beginning”. I know what you are thinking about. It is
basically a famous quote from a web series named “Dark”. Now how it relates to Python
programming?
If you researched on google, youtube, or any development communities out there, you
will find that people explained how you can master programming in let’s say some “x”
number
Well, the reality is like the logo of infinity which we can see above. In the programming
realm, there is no such thing as mastery. It’s simply a trial and error process. For example.
Yesterday I was writing some code where I was trying to print a value of a variable before
“UnboundLocalErrorException“.
Throughout your entire career, you will be seeing new errors and exceptions. Just remember
the
Now here is the main part. What approach to follow in order to master Python
Programming?
If you happened to learn some programming languages, then I am sure you are aware of what
I
am talking about. The “Hello World” program is like a tradition in the developer community.
If
you want to master any programming language, this should be the very first line of code we
should be seeking for.
print("Hello World")
Now once we have mastered the “Hello World” program in Python, the next step is to master
variables in python. Variables are like containers that are used to store values.
Variables in Python:
my_var = 100
As you can see here, we have created a variable named “my_var” to assign a value 100 to the
same.
The next outpost is to learn about data types. Here I have seen that there is a lot of confusion
between data types and data structures. The important thing to keep in mind here is that data
types represent the type of data. For example. in Python, we have something like int, string,
float,
etc. Those are called data types as they indicate the type of data we are dealing with.
While data structures are responsible for deciding how to store this data in a computer’s
memory.
my_str = "ABCD"
As you can see here, we have assigned a value “ABCD” to a variable my_str. This is
basically a
Again this is just the tip of the iceberg. There are lots of data types and data structures in
Python.
To give a basic idea about data structures in Python, here is the complete list:
1.Lists
2.Dictionary
3.Sets
4.Tuples
5.Frozenset
In any programming language, conditionals and loops are considered one of the backbone.
Python is no exception for that as well. This is one of the most important concepts that we
need
to master.
IF-ELIF-ELSE CONDITIONALS:
else:
print("Do nothing")
As you can see in the above example, we have created what is known as the if-elif-else ladder
FOR LOOP:
for i in "Python":
print(i)
PRO Tip:
Once you start programming with Python, you will be seeing that if we missed any white
spacing in python then python will start giving some errors. This is known as Indentation in
python. Python is very strict with indentation. Python is created with a mindset to help
everyone
While The Python Language Reference describes the exact syntax and semantics of the
Python language, this library reference manual describes the standard library that is
distributed
with Python. It also describes some of the optional components that are commonly included
in
Python distributions.
Python’s standard library is very extensive, offering a wide range of facilities as indicated
by the long table of contents listed below. The library contains built-in modules (written in C)
that provide access to system functionality such as file I/O that would otherwise be
inaccessible
designed to encourage and enhance the portability of Python programs by abstracting away
The Python installers for the Windows platform usually include the entire standard
library and often also include many additional components. For Unix-like operating systems
packaging tools provided with the operating system to obtain some or all of the optional
components.
components (from individual programs and modules to packages and entire application
To understand Python packages, we’ll briefly look at scripts and modules. A “script” is
something you execute in the shell to accomplish a defined task. To write a script, you’d type
your code into your favorite text editor and save it with the .py extension. You can then use
the
A module on the other hand is a Python program that you import, either in interactive
mode or into your other programs. “Module” is really an umbrella term for reusable code.
containing modules and maybe other folders that themselves may contain more folders and
modules. Conceptually, it’s a namespace. This simply means that a package’s modules are
note that every package is a module — but not every module is a package. A package folder
usually contains one file named __init__.py that basically tells Python: “Hey, this directory is
a
package!” The init file may be empty, or it may contain code to be executed upon package
initialization.
You’ve probably come across the term “library” as well. For Python, a library isn’t as
clearly defined as a package or a module, but a good rule of thumb is that whenever a
package
these terms or concepts aren’t entirely clear to you, we’ve got you! In this section, we’ll
cover
everything you’ll need to really grasp the pipeline of using Python packages in your code.
Let’s assume that we haven’t yet installed any packages. Python comes with a big
collection of pre-installed packages known as the Python Standard Library. It includes tools
for
a range of use cases, such as text processing and doing math. Let’s import the latter:
You might think of an import statement as a search trigger for a module. Searches are
strictly organized: At first, Python looks for a module in the cache, then in the standard
library
and finally in a list of paths. This list may be accessed after importing sys (another standard
library module).
The sys.path command returns all the directories in which Python will try to find a
package. It may happen that you’ve downloaded a package but when you try importing it,
you
get an error:
In such cases, check whether your imported package has been placed in one of Python’s
search paths. If it hasn’t, you can always expand your list of search paths:
At that point, the interpreter will have more than one more location to look for
When we had imported the math module, we initialized the math namespace. This means that
we can now refer to functions and classes from the math module by way of “dot notation”:
Assume that we were only interested in our math module’s factorial function, and that
we’re also tired of using dot notation. In that case, we can proceed as follows:
If you’d like to import multiple resources from the same source, you can simply
There is, however, always a small risk that your variables will clash with other variables in
your namespace. What if one of the variables in your code was named log, too? It would
overwrite the log function, causing bugs. To avoid that, it’s better to import the package as
we
did before. If you want to save typing time, you can alias your package to give it a shorter
name:
Aliasing is a pretty common technique. Some packages have commonly used aliases:
For instance, the numerical computation library NumPy is almost always imported as “np.”
However, this method poses serious risk since you usually don’t know all the names
contained in a package, increasing the likelihood of your variables being overwritten. It’s for
this reason that most seasoned Python programmers will discourage use of the wildcard * in
imports. Also, as the Zen of Python states, “namespaces are one honking great idea!”
How about packages that are not part of the standard library? The official repository for
finding and downloading such third-party packages is the Python Package Index, usually
referred to simply as PyPI . To install packages from PyPI, use the package installer pip:
pip can install Python packages from any source, not just PyPI. If you installed Python
using Anaconda or Miniconda , you can also use the conda command to install Python
packages.
While conda is very easy to use, it’s not as versatile as pip. So if you cannot install a
Reloading a Module
If you’re programming in interactive mode, and you change a module’s script, these changes
won’t be imported, even if you issue another import statement. In such case, you’ll want to
use
Packaging your code for further use doesn’t necessarily mean you’ll want it published
to PyPI. Maybe you just want to share it with a friend, or reuse it yourself. Whatever your
aim,
there are several files that you should include in your project. We’ve already mentioned the
__init__.py file.
Another important file is setup.py. Using the setuptools package, this file provides
detailed information about your project and lists all dependencies — packages required by
Publishing to PyPI is beyond the scope of this introductory tutorial. But if you do have
a package for distribution, your project should include two more files: a README.md
written
in Markdown, and a license. Check out the official Python Packaging User Guide ( PyPUG )
if
INSTALLING PACKAGES
It’s important to note that the term “package” in this context is being used to describe a
bundle of software to be installed (i.e. as a synonym for a distribution). It does not to refer to
the
kind of package that you import in your Python source code (i.e. a container of modules). It is
common in the Python community to refer to a distribution using the term “package”. Using
the
term “distribution” is often not preferred, because it can easily be confused with a Linux
This section describes the steps to follow before installing other Python packages.
Before you go any further, make sure you have Python and that the expected version is
available from your command line. You can check this by running:
Unix/macOS
python3 --version
Windows
You should get some output like Python 3.6.3. If you do not have Python, please install
the latest 3.x version from python.org or refer to the Installing Python section of the
Hitchhiker’s
Guide to Python.
NOTE
be run in a shell (also called a terminal or console). See the Python for Beginners getting
started
tutorial for an introduction to using your operating system’s shell and interacting with
Python.
NOTE
If you’re using an enhanced shell like IPython or the Jupyter notebook, you can run
system commands like those in this tutorial by prefacing them with a ! character:
!{sys.executable} --version
Python 3.6.3
It’s recommended to write {sys.executable} rather than plain python in order to ensure
that commands are run in the Python installation matching the currently running notebook
(which may not be the same Python installation that the python command refers to).
NOTE
Due to the way most Linux distributions are handling the Python 3 migration, Linux
users using the system Python without creating a virtual environment first should replace
the python command in this tutorial with python3 and the python -m pip command
with python3 -m pip --user. Do not run any of the commands in this tutorial with sudo: if you
get a permissions error, come back to the section on creating virtual environments, set one up,
Additionally, you’ll need to make sure you have pip available. You can check this by
running:
Unix/macOS
Windows
If you installed Python from source, with an installer from python.org, or via Homebrew you
should already have pip. If you’re on Linux and installed using your OS package manager,
you
may have to install pip separately, see Installing pip/setuptools/wheel with Linux Package
Managers.
If pip isn’t already installed, then first try to bootstrap it from the standard library:
Unix/macOS
Windows
Run python get-pip.py. 2 This will install or upgrade pip. Additionally, it will
Warning
system or another package manager. get-pip.py does not coordinate with those tools,
and may leave your system in an inconsistent state. You can use python get-pip.py --
While pip alone is sufficient to install from pre-built binary archives, up to date copies of
the setuptools and wheel projects are useful to ensure you can also install from source
archives:
Unix/macOS
Windows
See section below for details, but here’s the basic venv 3 command to use on a typical
Linux system:
Unix/macOS
source tutorial_env/bin/activate
Windows
This will create a new virtual environment in the tutorial_env subdirectory, and configure
location for a particular application, rather than being installed globally. If you are looking to
safely install global command line tools, see Installing stand alone command line tools.
Imagine you have an application that needs version 1 of LibFoo, but another application
requires version 2. How can you use both these applications? If you install everything into
/usr/lib/python3.6/site-packages (or whatever your platform’s standard location is), it’s easy
to
end up in a situation where you unintentionally upgrade an application that shouldn’t be
upgraded.
Or more generally, what if you want to install an application and leave it be? If an
application works, any change in its libraries or the versions of those libraries can break the
application.
Also, what if you can’t install packages into the global site-packages directory? For
In all these cases, virtual environments can help you. They have their own installation
directories and they don’t share libraries with other virtual environments.
Currently, there are two common tools for creating Python virtual environments:
venv is available by default in Python 3.3 and later, and installs pip and setuptools into
virtualenv needs to be installed separately, but supports Python 2.7+ and Python 3.3+,
and pip, setuptools and wheel are always installed into created virtual environments by
Using venv :
Unix/macOS
source <DIR>/bin/activate
Windows
Using virtualenv :
Unix/macOS
source <DIR>/bin/activate
Windows
For more information, see the venv docs or the virtualenv docs.
The use of source under Unix shells ensures that the virtual environment’s variables are set
within the current shell, and not in a subprocess (which then disappears, having no useful
effect).
In both of the above cases, Windows users should _not_ use the source command, but
should rather run the activate script directly from the command shell like so:
<DIR>\Scripts\activate
Managing multiple virtual environments directly can become tedious, so the dependency
management tutorial introduces a higher level tool, Pipenv , that automatically manages a
separate virtual environment for each project and application that you work on.
pip is the recommended installer. Below, we’ll cover the most common usage scenarios.
For more detail, see the pip docs, which includes a complete Reference Guide.
The most common usage of pip is to install from the Python Package Index using
name followed by an optional version specifier. PEP 440 contains a full specification of the
Unix/macOS
Windows
Unix/macOS
Windows
To install greater than or equal to one version and less than another:
Unix/macOS
Windows
Unix/macOS
Windows
In this case, this means to install any version “==1.4.*” version that’s also “>=1.4.2”.
pip can install from either Source Distributions (sdist) or Wheels, but if both are present
on PyPI, pip will prefer a compatible wheel. You can override pip`s default behavior by e.g.
using its –no-binary option.
Wheels are a pre-built distribution format that provides faster installation compared
If pip does not find a wheel to install, it will locally build a wheel and cache it for future
UPGRADING PACKAGES
Unix/macOS
Windows
To install packages that are isolated to the current user, use the --user flag:
Unix/macOS
Windows
For more information see the User Installs section from the pip docs.
Note that the --user flag has no effect when inside a virtual environment - all installation
If SomeProject defines any command-line scripts or console entry points, --user will cause
them
to be installed inside the user base’s binary directory, which may or may not already be
present
in your shell’s PATH. (Starting in version 10, pip displays a warning when installing any
scripts
to a directory outside PATH.) If the scripts are not available in your shell after installation,
you’ll
On Linux and macOS you can find the user base binary directory by running python -
m site --user-base and adding bin to the end. For example, this will typically
print ~/.local (with ~ expanded to the absolute path to your home directory) so you’ll
need to add ~/.local/bin to your PATH. You can set your PATH permanently
by modifying ~/.profile.
On Windows you can find the user base binary directory by running py -m site --user-
site and replacing site-packages with Scripts. For example, this could
You can set your user PATH permanently in the Control Panel. You may need to log out
REQUIREMENTS FILES
Unix/macOS
Windows
Unix/macOS
mercurial
branch
Windows
Unix/macOS
Windows
Unix/macOS
Windows
Unix/macOS
Windows
Unix/macOS
Windows
Unix/macOS
Windows
Install from a local directory containing archives (and don’t check PyPI )
Unix/macOS
Windows
To install from other data sources (for example Amazon S3 storage) you can create a
helper application that presents the data in a PEP 503 compliant index format, and use the --
./s3helper --port=7777
INSTALLING PRERELEASES
Find pre-release and development versions, in addition to stable versions. By default, pip
Unix/macOS
Windows
Unix/macOS