Python Course Notes Section 1-7 PDF
Python Course Notes Section 1-7 PDF
PROGRAMMER
Course Notes
Why Python?
⇢ Completely Free
⇢ A lot of built-in functionalities
Step 1
Go to www.anaconda.com
Step 2
Click on Download
03
Step 3
Choose Python 3 version
02
01
Introducing Spider
IDE
Integrated Development Environment
It has:
⇢ Source code area
⇢ Highlighted syntaxis
⇢ A place for running code
Spyder
Contains:
⇢ File editor
⇢ IPython Console
⇢ Variable explorer, File explorer and Help box
Spyder is a powerful scientific environment written in Python, for Python, and designed by and for
scientists, engineers and data analysts. It offers a unique combination of the advanced editing,
analysis, debugging, and profiling functionality of a comprehensive development tool with the data
exploration, interactive execution, deep inspection, and beautiful visualization capabilities of a
scientific package.
Beyond its many built-in features, its abilities can be extended even further via its plugin system
and API. Furthermore, Spyder can also be used as a PyQt5 extension library, allowing developers to
build upon its functionality and embed its components, such as the interactive console, in their own
PyQt software
Printing in a Nutshell
In Jupyter and Spyder, the last line in the input field is returned as an output (if there is anything to display).
Therefore to display an operation we can either write as the last line in the input field or use the print function.
Python Syntax
Forward Slash 2 Forward Slashes 2 Asterisks Single Quotation Marks Clear
Always gives a decimal Always gives an integer value To the power of Creates a string Clears the console.
number called Floating and discards the decimal part
Point Number (Float)
/ // ** ’’ clear
Whenever we are dealing with the print ( ) function, If we are printing a string, we’ve got some some extra
we can force the display of the operations characters to help us
(Word) end=’ ’ Backward Slash Backward Slash + t Backward Slash + n
Name error ⇢ always indicate the Defines an end character for a string . Escapes the following Indents the text, New line
string of characters with single or By default the end character is a new line. character. Tab command
double quotation marks
(Hi) end=’ ’ \ \t \n
Variables: General Rules
Asking the computer for more space in the main memory
01 ! However, we can
03
sensible names is a
good practice.
05
have underscores.
new_variable = 3 area=pi*radius**2
02 04
Strings: Input Function
Allows you to get user’s input NB:
Comment/Uncomment:
The user is
Symbol: #
requested to
make an input ⇢ highlight the area
⇢ right click
⇢ Comment/Uncomment
Type:
Returns the type of a value
⇢ str = string
Input(’string’)
⇢ int = integer
Keywords:
They are not allowed to be
used as variables names.
IF
== Checking for equality
Don’t
Want
Want
!= Not equal to
IF
<= Less than or equal to
Don’t have Have
money money
>= Grater than or equal to
Don’t
Buy
Buy
Or
If only one variable satisfies the condition
⇢ True
NOT
And
If both conditions are satisfied OR
⇢ True
Not
is 15 < 22 and 20 < 22 ⇢ True
Negates the result of the condition
Our variable
If statement
Meaning: If this condition
some_condition = False Else statement
evaluates to True, then
print the following line of Meaning: In every
code. if some_condition: other case, print
print(‘The variable \‘some_condition\’ is True’) something else
else:
print(‘The variable \‘some_condition\’ is False’)
List Example:
</>