Lecture 1: Introduction To Python
Lecture 1: Introduction To Python
What is Python?
Python is a popular programming language. It was created by Guido van Rossum, and released in 1991.
It is used for:
Why Python?
Python works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc).
Python has a simple syntax similar to the English language.
Python has syntax that allows developers to write programs with fewer lines than some other programming
languages.
Python runs on an interpreter system, meaning that code can be executed as soon as it is written. This means
that prototyping can be very quick.
Python can be treated in a procedural way, an object-orientated way or a functional way.
1
Installing Python on Windows 10:
1) Go to www.python.org
2) Click “Downloads” Link at the top of the page
3) Click “Download Python 3.5.2” (or whatever the 3.X version currently is:
2
4) When the
installation window comes up, click “Install Now”
a. You can choose to check the “Install launcher for all users (recommended) or not – either way should be
OK
b. You can choose to “Add Python 3.8 to PATH” or not – either way should be OK
c. Note: Depending on how Windows is set up, you might need to provide an administrator password to
install on your system at this point.
d. You can choose to “Customize Installation” if you want, especially if you want to install to a location
other than the default one shown. Generally I recommend installing to the default location unless you
have a problem doing so.
e. In any case, you might want to note the location of the installation in case you have difficulty later. If
you are specifying the location yourself, put it in a location you are likely to easily find/remember.
5) You should see Python installing at this point. When it finishes, you should see a screen that says the installation
was successful. You can click “Close”
Installing PyCharm
1) Go to www.jetbrains.com/pycharm
2) Click the “Download” button at top left (you can also scroll down the page and click the download link for the
community version directly)
6) Choose an installation location. I recommend letting it install in the suggested location. Click Browse if you
want to enter a new location, and when you are done selecting the location, click “Next”.
7) You can choose to select two options, after which you click “Next”
a. You can create a desktop shortcut (I suggest doing so). This will put a link to PyCharm on your desktop.
b. You can create associations (I suggest doing so). This means that when you open a python file (one with
a .py extension), it will open in PyCharm
8) Choose a start menu folder (I suggest leaving the default “Jetbrains” selected, but you can change it if you wish)
and click “Install”
9) Wait for installation to finish. At the end, you should receive a message screen that PyCharm is installed. You
can click “Finish”, and if you want to go ahead and run it, click the “Run PyCharm Community Edition” box
first. You have now installed PyCharm
Running PyCharm
1) The first time you run PyCharm, you will get a message box asking about importing settings. You can select
“I do not have a previous version of PyCharm or I do not want to import my settings” and click “OK”
2) The first time you run PyCharm, you will need to accept the privacy policy.
3) The first time you run PyCharm, you will have some “Initial Configuration” options. Just hit “OK”
4) You will now be at the intro screen for PyCharm. This will also be the intro screen when you start PyCharm
in the future without a recently opened project (if you do have a recently opened one you did not close
before exiting, it will automatically reopen to that one). Click on “Create New Project”
7) Try creating and running a program. Go up to the “File” menu and select “New” python file
Python Keywords and Identifiers
Keywords are the reserved words in Python.
We cannot use a keyword as a variable name, function name or any other identifier. They are used to
define the syntax and structure of the Python language.
In Python, keywords are case sensitive.
All the keywords except True, False and None are in lowercase and they must be written as they are.
The list of all the keywords is given below.
Python Identifiers
An identifier is a name given to entities like class, functions, variables, etc. It helps to differentiate
one entity from another.
global = 1
Output
a@ = 0
Output
output:
Hello world
website = "apple.com"
print(website)
website = "programiz.com"
print(website)
output:
apple.com
programiz.com
a, b, c = 5, 3.2, "Hello"
print (a)
print (b)
print (c)
output:
5
3.2
Hello
num1=9
num2=4
result=num1+num2
print(result)
output:
13
output:
sara adnan
Program 6: Combine two strings of the keyboard and print the result
output:
enter first name: ahmed
enter last name: zaid
ahmed zaid
Program 7: Combine two number of the keyboard and print the result
output:
enter first number: 4
enter second number: 5
the result: 9
output:
enter the number: 5
the square= 25
Program 8: Find the average three numbers of the keyboard and print the result
number1=int(input("Enter the first number: "))
number2=int(input("Enter the second number: "))
number3=int(input("Enter the third number: "))
total = number1 + number2 + number3
average = total / 3
print ("The average is: ",average)
output:
Enter the first number: 5
Enter the second number: 4
Enter the third number: 6
The average is: 5.0
output:
enter first number: 4
enter second number: 5
the result: 9