Professional Documents
Culture Documents
DFOR510 Week05 Func Flow Time
DFOR510 Week05 Func Flow Time
DFOR510 Week05 Func Flow Time
2
4
❑ Control Flow
❑ Learn how to navigate program for more efficient flow
❑ Understand the differences between break, continue, and pass
❑ Date/Time Stamps
❑ Identify common libraries associated with date/time stamp
❑ How to format date/time stamps for user readability
5
❑ Extracting timestamps from files
6
Ordinary 8
comments
▪ Most languages have a ‘main’ function that’s required to execute
programs – this is known as an entry point
▪ Not the case in Python
▪ However, we use main() function for best coding practices,
additionally…
1. We organize code into functions (def) or classes (class) to
optimize code
2. We call our entry point, main()
3. Function calls should be made from main() function
4. We utilize a special function to control what is executed when
scripts are run vs imported
9
▪ Why we use it:
▪ Code reuse
▪ Importing modules
10
IF __NAME__ == ‘__MAIN__’
From BB → Course Content → Week05… → Special_Main_Func_Exercise
Download:
❑ learnSpecialMain (.ipynb)
❑ Not using Juypyter Notebooks: Download learnSpecialMain (.py)
❑ specialMainFunc (.py)
❑ specialPart2 (.py)
11
QUICK CHECK 1
1. The ‘main’ function of a program is called the ______.
12
14
15
▪ Used within ‘while’ and ‘for’ loops
16
Output:
17
▪ Used within ‘while’ and ‘for’ loops
https://www.tutorialspoint.com/python/python_continue_statement.htm
18
19
Output:
20
▪ Can be used anywhere in a program
▪ Essentially a null operator
▪ Can be used as a placeholder for code that will be
developed
▪ Executes all code, unless a ‘break’ is encountered
21
22
From BB → Course Content → Week05... → ControlFlowExercises
❑ Download breakContPass (.ipynb or .py)
23
QUICK CHECK 2
Match the command to its definition
24
26
27
▪ Handles dates and times, separately and together
▪ datetime.datetime() – creates datetime object;
▪ Output: (YYYY, MM, DD, hr, min, sec, msec, tzone)
▪ datetime.datetime.now() – return current system time
▪ datetime.timedelta() – difference between 2 datetime
objects;
▪ Output is the difference in days, seconds, and
microsecond
▪ datetime.datetime.strftime() – used for formatting date and
time 28
▪ Functions reside in ‘os’ library
Main Function
4. https://docs.python.org/3/tutorial/modules.html
5. https://www.guru99.com/learn-python-main-function-with-examples-understand-main.html
6. https://realpython.com/python-main-function/
7. https://www.youtube.com/watch?v=sugvnHA7ElY
35
36
38
https://docs.python.org/3/library/datetime.html?highlight=datetime#strftime-strptime-behavior
Python Timestamps – strftime() formats (3)
39
https://docs.python.org/3/library/datetime.html?highlight=datetime#strftime-strptime-behavior
C
O
o
p
m
e
p
r
a
a
r
t
i
o
s
r
o
s
n
40
41