0% found this document useful (0 votes)
55 views33 pages

Unit I

The document provides an introduction to installing Python on Linux and Windows systems. It discusses downloading the appropriate installation file based on the operating system and version of Python. It also describes how to validate the installation by checking the Python and pip versions and listing installed packages.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views33 pages

Unit I

The document provides an introduction to installing Python on Linux and Windows systems. It discusses downloading the appropriate installation file based on the operating system and version of Python. It also describes how to validate the installation by checking the Python and pip versions and listing installed packages.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

IBM ICE (Innovation Centre for Education)

Welcome to:

Introduction to Python

9.1
Unit objectives IBM ICE (Innovation Centre for Education)
IBM Power Systems

After completing this unit, you should be able to :

• Give an Introduction to Python

• Install Python on your platform

• Learn different flavors of Python

• Execute Python programs in different ways

• Learn syntax of Python programming


History of Python
IBM ICE (Innovation Centre for Education)
IBM Power Systems

Introduction

Popular version : Python 2.7 –July 4, 2010


Current running : Python 3.6 - December 23, 2016

Latest release : Python 3.7 - June 27, 2018


What’s Python buzz? IBM ICE (Innovation Centre for Education)
IBM Power Systems

• General purpose programming language

• Named after Monty Python-British comedy group

• Used to do things from testing microchips at Intel

• Used to powering Instagram

• building video games ,popular in IoT, Data Science ,Big Data,AI and so on….

• Followed by millions of users worldwide


Why to Learn Python? IBM ICE (Innovation Centre for Education)
IBM Power Systems

Here we go with Python

• fast, lower learning-curve, user-friendly


• Plays well with others
• Runs everywhere
• Known for rich-ecosystem & utilities
• Major advantage is its breadth
• Has thousands of third-party modules and libraries
• Libraries/frameworks are mature and tested for 10+ years
Example IBM ICE (Innovation Centre for Education)
IBM Power Systems

Python tools for Scientific community


Features of Python IBM ICE (Innovation Centre for Education)
IBM Power Systems
• Does not need compilers to run python codes
• Its an interpreter
• Executes line by line
• Writing application, testing, deployment is faster
• Easy to integrate different modules
• Debugging is easier
• Rich data types, object-oriented
Python interpreter.. IBM ICE (Innovation Centre for Education)
IBM Power Systems
Growth IBM ICE (Innovation Centre for Education)
IBM Power Systems

Source https://stackoverflow.blog/
Strength of Python IBM ICE (Innovation Centre for Education)
IBM Power Systems

Python is too strong

Source https://stackoverflow.blog
Python use cases IBM ICE (Innovation Centre for Education)
IBM Power Systems
• Python is a scripting language like PHP, Perl, Ruby
• web programming (django, Zope, Google App Engine..)
• desktop applications (Blender 3D)
• Even for games (Pygames)
• Applications:Health,Finanace,Mathematical&Scientific,Vision,Database,Data science,Machine Learning
Flavors of Python
IBM ICE (Innovation Centre for Education)
IBM Power Systems
Python 2 vs Python 3 IBM ICE (Innovation Centre for Education)
IBM Power Systems
When would one choose 2.7 ? IBM ICE (Innovation Centre for Education)
IBM Power Systems

Users would choose 2.7 only under these below conditions :

• Many organisations who store Python Installers for releases in their repo’s have not adopted
to v3.6 so this may be a bottleneck for developers who want to explore the new features and
libraries in v3.6
.
• The user would choose earlier version if they are going to deploy apps on an environment
that they do not have control over - and since assuming the remote deployment location still
has 2.7 - then it is understandable to use 2.7.

• If the third party releases for the product does not support 3.6 - then it is apt to use the
earlier version.
Introduction to Python IBM ICE (Innovation Centre for Education)
IBM Power Systems
• Python is Open Source and is GPL compatible

• Python is pre-installed as default OS packages. ( like CentOS and RHEL )

• Installation is simple due to pip & setuptools.py supporting packages

• Python as it provides a web development framework for faster development and deployments
Introduction to Python IBM ICE (Innovation Centre for Education)
IBM Power Systems
Installation of Python IBM ICE (Innovation Centre for Education)
IBM Power Systems
Introduction to Python Versions of Python
Installation IBM ICE (Innovation Centre for Education)
IBM Power Systems
Introduction to Python Versions of Python
Installation IBM ICE (Innovation Centre for Education)
IBM Power Systems

Installation of Python on Linux

• Before you install, check if python is already installed ! ( command -v python3 on MacOS, or
type in python3 at the command prompt.)
• Python comes preinstalled on CentOS, RHEL lately and hence not required to be installed. If it is
not installed then follow the instructions in the download link provided.

• Here, you will install the python 3.6 on a Linux/UNIX server. Since there are variants to the UNIX
flavours - only DEBIAN is described here in this slide
Installation IBM ICE (Innovation Centre for Education)
IBM Power Systems

Installation of Python on Linux


• For more installation procedures on different Linux servers refer to this
https://www.python.org/downloads/

• For RPMS: https://www.python.org/download/releases/2.4/rpms/

• For other packages : https://www.python.org/downloads/release/python-364/


• Scroll down to the bottom of the page to the Files section, Here, there are links for gzip file,
XZ compressed files, ( and other OS as well )

• User would use the same Download URL, and choose the v2.7 and install it. Both versions
can co-exist.
Introduction to Python Versions of Python
Installation IBM ICE (Innovation Centre for Education)
IBM Power Systems

Installing Python on Windows ( same for 32 bit and 64 bit architecture)

• One has the option of installing Python in different ways, It can be either in gzip form,
Installer, or a web based installer

• Installing the gzip or source code and compiling is only if you want to install it locally.
• However the easier way is to install using the Windows Installer.

• Scroll down to the section in this link/URL where the “Files” are listed, and you will see
different flavours of installers, and for 32 bit and 64 bit processors as well.

• Choose the appropriate package for your platform - download and install.
Testing and Validating Installation IBM ICE (Innovation Centre for Education)
IBM Power Systems
• Validating the installation of both Python and pip.
• pip3 - the tool to support in installation of additional libraries for Python gets automatically installed when
user installs the v3.6
• To check if this is installed - open a command prompt and type in the command pip3 ( the related
command to check in version 2.7 is pip )
• pip3 —V ( double dash )
• This indicates the version of pip installed and at the end it will say the matching python version that this
is compatible with.
• Additional information on installing pip can be obtained from

https://pip.pypa.io/en/stable/installing/

• On a related note: one can upgrade pip by running the command


• pip install -U pip
• Once satisfied that the installation was successful, try listing the different package using the pip
command.
PIP3 LIST 1 of 1 IBM ICE (Innovation Centre for Education)
IBM Power Systems
• A sample pip list command should return something like this. ( This is just an example )

altgraph (0.10.2)
wscli (1.14.28)
bdist-mpkg (0.5.0)
bonjour-py (0.3)
botocore (1.8.32)
certifi (2018.1.18)
chardet (3.0.4)
click (6.7)
cloudant (2.3.1)
• next, explore the pip command by typing in
• pip3 —-help
PIP3 LIST 1 of 2 IBM ICE (Innovation Centre for Education)
IBM Power Systems

• Also, explore
• pip show command to list the package and it’s attributes
pip3 show python ( This is only a sample, Your output can vary )
• Name: Python
• Version: 2.7.10
• Summary: A high-level object-oriented programming language
• Home-page: http://www.python.org/2.7
• Author: Guido van Rossum and the Python community
• Author-email: [email protected]
• License: PSF license
• Location: /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-
dynload
• Requires:
Installation IBM ICE (Innovation Centre for Education)
IBM Power Systems
• Let’s just install a sample package called Cloudant ( this is a NoSQL DB)
$ pip3 install cloudant
• Collecting cloudant
• Downloading cloudant-2.8.1.tar.gz (54kB)
• 100% |████████████████████████████████| 61kB 205kB/s
• Collecting requests<3.0.0,>=2.7.0 (from cloudant)
• Using cached requests-2.18.4-py2.py3-none-any.whl
• Collecting certifi>=2017.4.17 (from requests<3.0.0,>=2.7.0->cloudant)
• Using cached certifi-2018.1.18-py2.py3-none-any.whl
• Collecting chardet<3.1.0,>=3.0.2 (from requests<3.0.0,>=2.7.0->cloudant)
• Using cached chardet-3.0.4-py2.py3-none-any.whl
• Collecting urllib3<1.23,>=1.21.1 (from requests<3.0.0,>=2.7.0->cloudant)
• Using cached urllib3-1.22-py2.py3-none-any.whl
• Collecting idna<2.7,>=2.5 (from requests<3.0.0,>=2.7.0->cloudant)
• Using cached idna-2.6-py2.py3-none-any.whl
• Installing collected packages: certifi, chardet, urllib3, idna, requests, cloudant
• Running setup.py install for cloudant ... done
• Successfully installed certifi-2018.1.18 chardet-3.0.4 cloudant-2.8.1 idna-2.6 requests-2.18.4 urllib3-1.22
• Now, run the pip3 list command and validate that the Cloudant is installed.
Checkpoint (1 of 2) IBM ICE (Innovation Centre for Education)
IBM Power Systems
1 MARK QUESTION

1.Is it a good practice to write python programs in file names that ends with a .py ?
– Yes
– No.
2.‘pip’ and ‘setuptools.py’ are supporting 3rd party tools that aid in installing Python modules and other
libraries.
– Yes
– No
3.Basic Programs written for version 2.7 can be run on version 3.6 as well in general ?
– Yes
– No
4.python —version command will indicate the version of the Python executable
– Yes
– No
5.‘python’ and ‘python3’ are the executable names for python and python3 programming Language
– Yes
– No
6. Python is an interpreter and does require code to be compiled before executing.
– True
– False
Checkpoint solutions (1 of 2) IBM ICE (Innovation Centre for Education)
IBM Power Systems

• 1. Yes - all programs need a suffix and in the case of Python programs - they end with .py. It
helps in identifying that they are Python scripts.

• 2. Yes, pip and setuptools.py are 3rd party tools that aid in installation of libraries and
modules. They are installed as part of the v3.6 by default.

• 3. Yes, Generally, all code written for v2.7 will and should work for v3.6.

• 4. Yes, python —version will print the v2.7 and python3 —version will print the v3.6

• 5. python is the name of the v2.7 executable and python3 is the name of the v3.6 executable.

• 6. False, Python is an interpreter and does not need to be compiled for it to be run.
Checkpoint (2 of 2) IBM ICE (Innovation Centre for Education)
IBM Power Systems
7.Data Types in Python are similar to Fortran Programming Language
– True
– False
8. Python syntax is indent based, and English like
– True
– False
9. Invoking the python interpreter command line can be terminated by
– Ctrl-D
– Ctrl-C

10. Python code can be executed by mentioning the location of the executable in first line of the script
– True
– False

11. Python lets integration of different components seamlessly into it’s code.
– True
– False
12. Python is fast in execution as it is a interpreter, since compilation is not done.
– True
– False

13. How do you get out of a Python command interpreter,


– quit()
– quit
Checkpoint solutions (2 of 2) IBM ICE (Innovation Centre for Education)
IBM Power Systems

• 7. False, Data Types are similar to C programming language.

• 8. True, Python is indent based and English like.

• 9. Ctrl-D

• 10. True, #!/usr/bin/python

• 11. True

• 12. False, Python tends to be slow in execution compared to compiled languages like Java
and others as it is an Interpreter.

• 13. quit() - this is the method to get out of the Interactive command interpreter.
Question bank IBM ICE (Innovation Centre for Education)
IBM Power Systems

2 MARKS QUESTIONS
• 1. Comments in Python is indicated by a #, or triple quotes, or triple double quotes sign in the beginning
of the line.
– True
– False
• 2. Data Type of ‘x’ is obtained by “ print type(x) “
– True
– False
• 3. Python language programming is not Case-Sensitive
– True
– False
• 4. Multi Line statements are indicated by a ‘*’ at end of the line.
– True
– False
• 5. Multiple statements are allowed in a single line if they are separated by a semicolon ‘;’.
– True
– False
• 6. The “python -v” flag reports the verbose debug output when program is run.
– True
– False
Question bank IBM ICE (Innovation Centre for Education)
IBM Power Systems

• 4 MARKS QUESTION

• 1. Write a program that will read the number of arguments and print the arguments ? (
http://www.pythonforbeginners.com/system/python-sys-argv)

• 2.Explain any two popular applications written in Python.

• 3. What are the advantages and disadvantages of Python programming language.

• 4. When does one use Python 2.7 Vs Python 3.6

• 5. Install a Data Analysis package using pip command on your platform


pip3 install matplotlib, Check if package is installed by “pip3 list”

• 6. Import ‘os’ package in your sample program, and print the os.name.
import os
print os.name
Question bank IBM ICE (Innovation Centre for Education)
IBM Power Systems

• 8 MARKS QUESTION

• 1. Write a program that will import os, and print os.getcwd() and os.uname().
Refer to this link for additional help. https://docs.python.org/2/library/os.html

• 2.Write a program that will import sys, and print sys.version_info


• https://docs.python.org/2/library/sys.html

• 3. Write a program that will print the arguments passed to the program. e.g python.
print_args.py. one two three
Hint : use sys.argv method.

• 4.Write a program, that will print today’s date using ‘from datetime import date’ and print
date.today()

• 5.Write a program and include help(), and when executed will print the help menu ( e.g:
help() )

• 6. Write a program a) import os, and then b) print dir (os) and check results.
Unit summary IBM ICE (Innovation Centre for Education)
IBM Power Systems

Having completed this unit, you should be able to:

• Give an Introduction to Python

• Install Python on your platform

• Learn different flavors of Python

• Execute Python programs in different ways

• Learn syntax of Python programming

You might also like