Python Intro - Day 1
Python Intro - Day 1
www.kfupm.edu.sa
Python for Beginners 2
Table of Contents
1. What is a computer programming language ...................................................... 3
2. What is Python ................................................................................................... 5
3. Python Usages ................................................................................................... 5
4. Python’s major features ..................................................................................... 6
4.1 It’s easy to read and write.......................................................................... 6
4.2 Variable Types adjusted automatically or dynamically ............................... 7
4.3 Garbage Collection..................................................................................... 7
5. Python History ................................................................................................... 9
6. Python Installation ........................................................................................... 10
6.1 Python Version......................................................................................... 11
8. Resources......................................................................................................... 12
8.1 websites ................................................................................................... 12
https://www.python.org/downloads/release/python-3105/ ........................ 12
www.kfupm.edu.sa
Python for Beginners 3
www.kfupm.edu.sa
Python for Beginners 4
• A
www.kfupm.edu.sa
Python for Beginners 5
2. What is Python
Python is a computer programming language. Or, in other words, a vocabulary and set
of grammatical rules for instructing a computer to perform tasks. Its original creator, Guido van
Rossum, named it after the BBC television show ‘Monty Python’s Flying Circus.’
Hence, you’ll find that Python books, code examples, and documentation
sometimes contain references to this television show.
• Python = Simplicity
• It is an open-source language
• It is a high-level language
• It is interpreted
• It is both object-oriented and functional
• It is portable
• It is extensible and embeddable
• It comes with a vast collection of libraries
3. Python Usages
Python is used in many places. With its rich library base, it scales just as well to
large systems. To illustrate: the original creators of YouTube used Python for the
most part! Dropbox, as far as I know, is primarily written in Python as well. And
Instagram’s entire backend and website are written in Python as well.
You can use Python to automate tasks, perform calculations, create user
interfaces, create website backends, access databases, download information
from the Internet, etc. Some real world applications use python for;
1. Web Development
2. Game Development
3. Scientific and Numeric Applications
4. Artificial Intelligence and Machine Learning
www.kfupm.edu.sa
Python for Beginners 6
5. Desktop GUI
6. Software Development
7. Enterprise-level/Business Applications
8. Education programs and training courses
9. Language Development
10.Operating Systems
11.Web Scraping Applications
12.Image Processing and Graphic Design Applications
13.Python is extremely popular in data sciences. Many data scientists use Python
for their day-to-day work.
Many people say that Python comes with batteries included. It’s a fun way of
stating that it includes a comprehensive base library. In addition to this, you can
find hundreds of thousands of external packages contributed by the enormous
community. You’ll find supporting base libraries and packages for pretty much
anything you want to accomplish.
def bigger_than_five(x):
# The contents of a function are indented
if x > 5:
print("X is bigger than five")
else:
print("x is 5 or smaller")
Because indentation is required, the Python language does not need curly braces
to group code blocks like Java, C, and C#.
www.kfupm.edu.sa
Python for Beginners 7
Now let’s look at Python variables. In Python, we can do exactly the same without
types:
my_name = "Zafar"
my_age = 40
my_salary = 1234.56
As you can see, the Python variant is a lot cleaner and easier on the eyes!
When running this code, Python dynamically finds out the type of our variables.
Say, for example, I’d like to know my yearly income by multiplying my salary by
12. I’d need to do the following:
my_income = my_salary * 12
Python will look at my_salary, see that it is a floating-point value, and perform the
math. If my_salary would have been a string, Python wouldn’t complain though. It
would detect it’s a string and just create a new one, consisting of 12 repetitions of
that string! Java, however, would fail with an error in such cases.
www.kfupm.edu.sa
Python for Beginners 8
Each variable you declare takes up space in your computer’s memory. This can
add up quickly, especially when you create programs that run for a long time. So,
you need a way to clean up variables that you don’t use anymore.
In some languages, you need to perform this cleanup explicitly. This is prone to a
type of error called a memory leak. If you make a little mistake and forget to clean
up, your software will slowly eat up available memory. Lucky for us, Python’s
garbage collector automatically cleans up unused variables!
www.kfupm.edu.sa
Python for Beginners 9
5. Python History
www.kfupm.edu.sa
Python for Beginners 10
6. Python Installation
download Python for Windows from the
website https://www.python.org/downloads/windows/ . Click on the "Latest Python 3
Release - Python x.x.x" link. If your computer is running a 64-bit version of
Windows, download the Windows x86-64 executable installer. Otherwise, download
the Windows x86 executable installer . After downloading the installer, you should run it
(double-click on it) and follow the instructions there.
One thing to watch out for: During the installation, you will notice a window
marked "Setup". Make sure you tick the "Add Python 3.6 to PATH" or 'Add Python
to your environment variables" checkbox and click on "Install Now", as shown
here (it may look a bit different if you are installing a different version):
When the installation completes, you may see a dialog box with a link you can
follow to learn more about Python or about the version you installed.
www.kfupm.edu.sa
Python for Beginners 11
Alternatively, you can right-click the Start button and select Windows
PowerShell or Windows PowerShell (Admin).
With the command line open, type in the following command and press Enter :
C:\> python -V
Python 3.6.4
www.kfupm.edu.sa
Python for Beginners 12
8. Resources
8.1 websites
https://www.python.org/downloads/release/python-3105/
www.kfupm.edu.sa