2. PYTHON PROGRAMMING TOPICS
I
• Introduction to Python Programming
II
• Python Basics
III
• Controlling the Program Flow
IV
• Program Components: Functions, Classes, Modules, and Packages
V
• Sequences (List and Tuples), and Dictionaries
VI
• Object-Based Programming: Classes and Objects
VII
• Customizing Classes and Operator Overloading
VIII
• Object-Oriented Programming: Inheritance and Polymorphism
IX
• Randomization Algorithms
X
• Exception Handling and Assertions
XI
• String Manipulation and Regular Expressions
XII
• File Handling and Processing
XIII
• GUI Programming Using Tkinter
9. DIVIDE-AND-CONQUER ALGORITHM
most computer programs that solve real-world problems are
complex/large
the best way to develop and maintain a large program is to
construct it from smaller pieces or components
10. PYTHON PROGRAM COMPONENTS
functions
classes
modules
collection of functions & classes
packages
collection of modules
41. VARIABLE SCOPE
all variables in a program may not be accessible at all locations
in that program
the scope of a variable determines the portion of the program
where you can access a particular variable
42. VARIABLE SCOPE
variables that are defined inside a function body have a local
scope, and those defined outside have a global scope
inside a function, a local variable takes precedence over a
global variable of the same name
possible workaround:
change the variable names to avoid collision
45. PYTHON FUNCTIONS (ARGUMENTS)
You can call a function by using the
following types of formal arguments:
Required Arguments
Default Arguments
Keyword Arguments
Variable-Length Arguments
48. PYTHON FUNCTIONS (ARGUMENTS)
Keyword Arguments
the caller identifies the arguments by the parameter name as
keywords, with/without regard to positional order
52. NAMESPACES
refers to the current snapshot of loaded
names/variables/identifiers/folders
functions must be loaded into the memory before you could call
them, especially when calling external functions/libraries
81. PRACTICE EXERCISE 1
Compute the factorial of a number n:
• n is a number inputted by the user
• make a factorial function and call it to solve
the factorial of n
82. PRACTICE EXERCISE 2
Compute the sum of a number range, say, from a to b, inclusive:
• a, b are numbers inputted by the user
• make a sum_range(a, b) function and call it to solve the
sum of all numbers from a to b, including a and b.
84. REFERENCES
Deitel, Deitel, Liperi, and Wiedermann - Python: How to Program (2001).
Disclaimer: Most of the images/information used here have no proper source
citation, and I do not claim ownership of these either. I don’t want to reinvent the
wheel, and I just want to reuse and reintegrate materials that I think are useful or
cool, then present them in another light, form, or perspective. Moreover, the
images/information here are mainly used for illustration/educational purposes
only, in the spirit of openness of data, spreading light, and empowering people
with knowledge.