Python is an interpreted, object-oriented programming language that can be used for many types of applications. It was created by Guido van Rossum in the 1980s and takes influence from languages like ABC, Modula-3, C, C++, Algol-68, SmallTalk, and Unix shell scripting. Python code can be written and executed with either an interactive interpreter or scripts, and Python is widely used for web development, data analysis, artificial intelligence, and scientific computing.
3. Python is a general-purpose interpreted, interactive, object-oriented, and high-level
programming language. It was created by Guido van Rossum during 1985- 1990.
Python is derived from many other languages, including ABC, Modula-3, C, C++, Algol-
68, SmallTalk, and Unix shell and other scripting languages.
Python’s elegant syntax and dynamic typing, together with its interpreted nature, make
it an ideal language for scripting and rapid application development in many areas on
most platforms.
The Python interpreter and the extensive standard library are freely available in source
or binary form for all major platforms from the Python Web site, https://www.python.org/
Professionally, Python is great for backend web development, data analysis, artificial
intelligence, and scientific computing. Many developers have also used Python to build
productivity tools, games, and desktop apps.
4. • Scripting and Automation
It is a very useful capability that allows you to type in a program and to have it
executed immediately in an interactive mode.
The code is written in the form of scripts and get executed
Machine reads and interprets the code
Error checking is done during Runtime
Once the code is checked, it can be used several times. So by automation, you can
automate certain tasks in a program.
Why Python
5. Data Science
Python is the leading language of many data scientist.
For years, academic scholars and private researchers were using the MATLAB
language for scientific research but it all started to change with the release of
Python numerical engines such as ‘Numpy’ and ‘Pandas’.
Computer Graphics
Python is largely used in small, large, online or offline projects.
It is used to build GUI and desktop applications.
It uses ‘Tkinter‘ library to provide fast & easy way to create applications.
6. Artificial Intelligence
You can actually make a machine mimic the human brain which has the power to
think, analyze and make decisions.
Furthermore, libraries such as Keras and TensorFlow bring machine learning
functionality into the mix.
It gives the ability to learn without being explicitly programmed. Also, we have
libraries such as openCv that helps computer vision or image recognition.
Web Development
Python has an array of frameworks for developing websites.
The popular frameworks are Django, Flask, Pylons etc. Since these frameworks
are written in Python, its the core reason which makes the code a lot faster and
stable.
We can also perform web scraping where you can fetch details from any other
websites.
7. Portable & Extensible
The portable and extensible properties of Python allow you to perform cross-
language operations seamlessly.
Python is supported by most platforms present in the industry today ranging from
Windows to Linux to Macintosh, Solaris, Play station, among others.
Simple & Easy To Learn
• Python is Free & open source
• High-level
• Interpreted
• Blessed with large community
8.
9. Installing Python
Python is preinstalled on most Unix or Linux
systems.
But for Windows Operating Systems user
can download from the
https://www.python.org/downloads/
From the link, download the latest version of
python IDE and install.
After Installing the Python go to start menu
you will find Python command line and IDLE
Python GUI.
10. Python Code Execution
Source code is translated to byte code, which is then run by the Python virtual
machine.
Code is automatically compiled but then it is interpreted.
11. Local Environment Setup
Open a terminal window and type "python" to find out if it is already installed and
which version is installed.
12. Setting up PATH
Programs and other executable files can be in many directories, so operating
systems provide a search path that lists the directories that the OS searches for
executables.
The path is stored in an environment variable, which is a named string maintained by
the operating system. This variable contains information available to the command
shell and other programs.
The path variable is named as PATH in Unix or Path in Windows
Setting path at Windows
To add the Python directory to the path for a particular session in Windows −
At the command prompt − type path %path%;C:Python and press Enter.
Note − C:Python is the path of the Python directory
13. Interactive Mode and Script Mode are the two main modes which are used in
Python Programming Language.
The basic differences between these two modes are as follows:
Interactive mode is used when an user wants to run one single line or one block
of code. It runs very quickly and gives the output instantly.
Example: Python command line.
Script Mode, on the other hand , is used when the user is working with more than
one single code or a block of code.
Example: IDLE Python GUI
14.
15. Python Identifiers
A Python identifier is a name used to identify a variable, function, class, module or
other object.
An identifier starts with a letter A to Z or a to z or an underscore (_) followed by zero
or more letters, underscores and digits (0 to 9).
Python does not allow punctuation characters such as @, $, and % within identifiers.
Python is a case sensitive programming language. Thus, a and A are two different
identifiers in Python.
16. Here are naming conventions for Python identifiers −
• Class names start with an uppercase letter. All other identifiers start with a
lowercase letter.
• Starting an identifier with a single leading underscore indicates that the identifier
is private.
• Starting an identifier with two leading underscores indicates a strongly private
identifier.
• If the identifier also ends with two trailing underscores, the identifier is a
language-defined special name
17. and exec not
assert finally or
break for pass
class from print
continue global raise
def if return
del import try
elif in while
else is with
except lambda yield
These are reserved words and you cannot use them as constant or variable or any
other identifier names. All the Python keywords contain lowercase letters only.
18. Python uses indentation for blocks, instead of curly braces.
Both tabs and spaces are supported, but the standard indentation requires
standard Python code to use four spaces.
Lines and Indentation
if True:
print "True"
else:
print "False"
Thus, in Python all the continuous lines indented with same number of spaces would
form a block.
19. Comments in Python
A hash sign (#) that is not inside a string literal begins a comment.
All characters after the # and up to the end of the physical line are part of the
comment and the Python interpreter ignores them.
# First comment statement
print "Hello, Class!" # second comment
Output : Hello Class
Triple-quoted string is also ignored by Python interpreter and can be used as a
multiline comments:
'''
This is a multiline
comment.
'''
25. num1 = 1.5
num2 = 6.3
# Add two numbers
sum = num1 + num2
# Display the sum
print('The sum of {0} and {1} is {2}'.format(num1, num2, sum))
Swapping of 2 Nos
x = 5
y = 10
x, y = y, x
print("x =", x)
print("y =", y)