04-Introduction To Python
04-Introduction To Python
To Python
Programming
Introduction to Python programming Course Outline
⬡ A. 36 ⬡ A. 36
⬡ B. 15 ⬡ B. 15
⬡ C. 27 ⬡ C. 27
Q3. 4 // 2 + 5 *
(1+2) Q4. 3 + 3 / 3 - 3 Q5. (3 + 3) / (3 – 3)
⬡ A. 21 ⬡ A. 1 ⬡ A. 1
⬡ B. 9 ⬡ B. ZeroDivisionError ⬡ B. ZeroDivisionError
⬡ C. 17 ⬡ C. 0 ⬡ C. 0
9
Introduction to Python programming Course Outline
Boolean algebra is the type of algebra performed on Boolean values only. Those
are, True and False (0 and 1)
Boolean & Comparison and Logic
Comparisons yield a Boolean value
(Assume a = 10 & b = 20)
Boolean & Comparison and Logic
Like multiplication: 1 x 0 = 0
Like addition: 1 + 0 = 1
Quiz Time!
Q1. 5 > 10 and 3 > Q3. -10 < 3 and 0 <
2 Q2. 5 > 10 or 3 > 2 2
Q4. (not 1 == 10) and 2 >= Q5. 0 > -1 and (1 == 2 and (not 1 !=
2 2))
⬡ A. True ⬡ A. True
⬡ B. False ⬡ B. False
15
Introduction to Python programming Course Outline
⬡ A. Sloths ⬡ A. It divides by 7
⬡ B. Cats ⬡ B. It divides by 3
⬡ C. No print ⬡ C. Doesn’t divide
18
Introduction to Python programming Course Outline
⬡ A. 2, 1, 0 ⬡ A. 12
⬡ B. 2, 1, 0, -1, -2, -3, -4, -5 ⬡ B. 9
⬡ C. 2, 1, 0, -1, -2, -3, -4 ⬡ C. 7
22
Introduction to Python programming Course Outline
More functions:
https://www.w3schools.com/python/
python_ref_dictionary.asp
Quiz Time! Q2. list1 = [1, 2, 3, [1, 2], (1, 2,
Q1. list1 = ['physics', 'chemistry', 1997, 2000] 3)]
print(list1[1][-1]) print(len(list1))
⬡ A. p ⬡ A. 8
⬡ B. c ⬡ B. 5
⬡ C. y ⬡ C. 6
⬡ D. Error
Advanced if conditions
if x > 0:
y=x*2
else:
y = x * -1
y = x * 2 if x > 0 else x * -1
Advanced for loop
For loop can be used to iterate over any iterable
Q1
.
⬡ A. 2
Q2
.
⬡ B. 5
⬡ C. 3
⬡ A. J, h, o, n, It’s John!
⬡ B. J, h, n, It’s John!
⬡ C. J, h, n
45
Introduction to Python programming Course Outline
Same as
Quiz Time!
What will be the output of the following statement:
Q1
.
⬡ A. 121
⬡ B. 9
⬡ C. 49
48
Introduction to Python programming Course Outline
50
Introduction to Python programming Course Outline
-
-
‘else’ : will execute if no errors were caught
‘finally’ : will execute whether there were
errors caught or not (always execute)
Introduction to Python programming Course Outline
-
Python can open text files in three modes:
-
Read mode (r)
-
Write mode (w)
Append mode (a)
⬡ B. Welcome
ViewersViewersViewers
⬡ C. Welcome
Viewers,Viewers,Viewers
⬡ D. Welcome
61
Introduction to Python programming Course Outline
Python supports a lot of functions and operators that are built inside it
There are a bunch of other useful functions in Python like map, filter & reduce
⬡ map(function, list) – applies a certain function on each element in the list and
returns a new list with those values
Map, Filter, Reduce
⬡ filter(function, list) – applies a filter function on the list and returns the values that
have a True value on the filter function
Map, Filter, Reduce
⬡ reduce(function, list) – applies a function on the list that reduces all elements
into a single value (like a sum) and returns that value
Lambda Expressions
In Python, Lambda expressions are used to define
an anonymous function - a function with no name
that can’t be called
Q1 Q2
. .
73
Introduction to Python programming Course Outline