Python - Lecture 01 AM
Python - Lecture 01 AM
➢
Variables, expressions, statements & Conditional execution
Data Visualisation
NumPy Library
Pandas Library
Cluster Analysis Algorithms in Python
Classification Algorithms 1: Decision Tress & Random Forest
Classification Algorithms 2: SVM, ANN and Deep ANN
❖
❖
❑
✓
☺
✓
✓
➢
➢
▪ One of the most powerful features of a programming language is the ability
to deal with and manipulate variables.
▪ A variable is a name that refers to a value (string, integer, double,…)
▪ An assignment statement creates new variables and gives them values:
>>> message = ‘I … am …… Iron Man'
>>> n = 17
>>> pi = 3.1415926535897931
▪ Comments: Very good idea to add comments to your code to know what
this piece of code is about.
▪ In Python, we use # to add a comment. Everything from the # to the end of
the line is ignored:
# compute the percentage of the hour that has elapsed
percentage = (minute * 100) / 60
▪ To display the value of a variable, you can use a print
statement:
>>> print(n)
17
>>> print(pi)
3.141592653589793
▪ To get the type of a variable:
>>> print (type(message))
<class 'str'>
>>> print (type(n))
<class 'int'>
>>> print (type(pi))
<class 'float'>
▪ Variable name can contain upper and lower case letters,
numbers and the underscore character
▪ A variable name must start with a letter or the underscore
character.
▪ A variable name CANNOT start with a number.
▪ A variable name can only contain alpha-numeric characters and
underscores (A-z, 0-9, and _ ) Variable names are case-sensitive
(age, Age and AGE are three different variables)
▪ Examples:
>>> 76trombones = 'big parade'
SyntaxError: invalid syntax
>>> more@ = 1000000
SyntaxError: invalid syntax
>>> class = 'Advanced Theoretical Zymurgy'
SyntaxError: invalid syntax
▪ There are a lot of words or statements in Python that have a
special meaning, role and/or function
▪ You cannot name a variable after one of these reserved
words
▪ You cannot use them as a variable name!
▪ e.g. You can’t have a variable called class
▪ Example:
>>> class = 'Advanced Theoretical Zymurgy'
SyntaxError: invalid syntax
▪ Some of Python’s reserved keywords:
and del from None True as elif global
nonlocal try assert else if not while Break
except import or with class False in pass
yield continue finally is raise async def
for lambda return await
❑ Operators are special symbols that represent computations like addition and multiplication.
❑ There has been a change in the division operator between Python 2.x and Python 3.x. In Python 3.x, the
result of this division is a floating point result:
❑ The division operator in Python 2.0 would divide two integers and truncate the result to an integer:
❑ Order of operations: Parentheses, Exponentiation, Multiplication and Division and then Addition and
Subtraction
❑ Operators with the same precedence are evaluated from left to right
❑
❑
❑
❑
❑
❑
❑
❑
❑
❑
❑
❑
❑
❑
❑
❑
Enter score: 0.95
A
Assume that the number is stored as a variable. What mathematical operator could you
use to solve these exercises? If an integer x is divisible by an integer y, what does that
mean? Try your programs on a number of examples.
◼