0% found this document useful (0 votes)
36 views

Python Intro - Day 1

Python introduction

Uploaded by

nice guys
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

Python Intro - Day 1

Python introduction

Uploaded by

nice guys
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Python for Beginners 1

Python for Beginners


Python Introduction

Prepared By: M. Zafar ul Malik

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

In today’s lecture we will develop an understanding about;

1. A computer programming language.


2. What is Python?
3. Python usages?
4. Python’s major features
5. Python’s history
6. Python Installation
7. Introduction to Python Basics

1. What is a computer programming language


• A programming language is a computer language that is used by
programmers (developers) to communicate with computers. It is a set of
instructions written in any specific language (C, C++, Java, Python) to
perform a specific task.

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.

What makes Python the “Best of the Best?”

• 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.

4. Python’s major features


4.1 It’s easy to read and write
In Python, we need to indent all code blocks to the same level. Here’s an example
of this at work.

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

4.2 Variable Types adjusted automatically or dynamically


Here are a few variable declarations in Java:

String myName = "Zafar";

int myAge = 40;

float mySalary = 1234.50;


In a strongly typed language, you need to specify the exact type of each variable,
like String, int, and float. It gets even uglier when objects are involved.

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.

4.3 Garbage Collection


Python has the concept of variables. A variable allows you to store any value like a
number, a string of text, or even bigger objects.

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

6.1 Python Version


To check if you already have Python on your Windows machine, first open a
command-line application, such as PowerShell.

Here’s how you open PowerShell:

1. Press the Win key.


2. Type PowerShell.
3. Press Enter .

Alternatively, you can right-click the Start button and select Windows
PowerShell or Windows PowerShell (Admin).

You can also use cmd.exe or Windows Terminal.

With the command line open, type in the following command and press Enter :

C:\> python --version


Python 3.6.4
Using the --version switch will show you the version that’s installed. Alternatively,
you can use the -V switch:

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

You might also like