<p>This textbook discusses the design and implementation of basic algebraic graph algorithms, and algebraic graph algorithms for complex networks, employing matroids whenever possible. The text describes the design of a simple parallel matrix algorithm kernel that can be used for parallel processing
A Beginners Guide to Python 3 Programming (Undergraduate Topics in Computer Science)
β Scribed by John Hunt
- Publisher
- Springer
- Year
- 2019
- Tongue
- English
- Leaves
- 440
- Edition
- 1st ed. 2019
- Category
- Library
No coin nor oath required. For personal study only.
β¦ Synopsis
This textbook on Python 3 explains concepts such as variables and what they represent, how data is held in memory, how a for loop works and what a string is. It also introduces key concepts such as functions, modules and packages as well as object orientation and functional programming. Each section is prefaced with an introductory chapter, before continuing with how these ideas work in Python.
Topics such as generators and coroutines are often misunderstood and these are explained in detail, whilst topics such as Referential Transparency, multiple inheritance and exception handling are presented using examples.
A Beginners Guide to Python 3 Programming provides all you need to know about Python, with numerous examples provided throughout including several larger worked case studies illustrating the ideas presented in the previous chapters.
β¦ Table of Contents
Preface
Chapter Organization
What You Need
Using an IDE
Downloading the PyCharm IDE
Setting Up the IDE
Conventions
Example Code and Sample Solutions
Contents
1 Introduction
1.1 What Is Python?
1.2 Python Versions
1.3 Python Programming
1.4 Python Libraries
1.5 Python Execution Model
1.6 Running Python Programs
1.6.1 Interactively Using the Python Interpreter
1.6.2 Running a Python File
1.6.3 Executing a Python Script
1.6.4 Using Python in an IDE
1.7 Useful Resources
2 Setting Up the Python Environment
2.1 Introduction
2.2 Check to See If Python Is Installed
2.3 Installing Python on a Windows PC
2.4 Setting Up on a Mac
2.5 Online Resources
3 A First Python Program
3.1 Introduction
3.2 Hello World
3.3 Interactive Hello World
3.4 Variables
3.5 Naming Conventions
3.6 Assignment Operator
3.7 Python Statements
3.8 Comments in Code
3.9 Scripts Versus Programs
3.10 Online Resources
3.11 Exercises
4 Python Strings
4.1 Introduction
4.2 What Are Strings?
4.3 Representing Strings
4.4 What Type Is String
4.5 What Can You Do with Strings?
4.5.1 String Concatenation
4.5.2 Length of a String
4.5.3 Accessing a Character
4.5.4 Accessing a Subset of Characters
4.5.5 Repeating Strings
4.5.6 Splitting Strings
4.5.7 Counting Strings
4.5.8 Replacing Strings
4.5.9 Finding Sub Strings
4.5.10 Converting Other Types into Strings
4.5.11 Comparing Strings
4.5.12 Other String Operations
4.6 Hints on Strings
4.6.1 Python Strings Are Case Sensitive
4.6.2 Function/Method Names
4.6.3 Function/Method Invocations
4.7 String Formatting
4.8 String Templates
4.9 Online Resources
4.10 Exercises
5 Numbers, Booleans and None
5.1 Introduction
5.2 Types of Numbers
5.3 Integers
5.3.1 Converting to Ints
5.4 Floating Point Numbers
5.4.1 Converting to Floats
5.4.2 Converting an Input String into a Floating Point Number
5.5 Complex Numbers
5.6 Boolean Values
5.7 Arithmetic Operators
5.7.1 Integer Operations
5.7.2 Negative Number Integer Division
5.7.3 Floating Point Number Operators
5.7.4 Integers and Floating Point Operations
5.7.5 Complex Number Operators
5.8 Assignment Operators
5.9 None Value
5.10 Online Resources
5.11 Exercises
5.11.1 General Exercise
5.11.2 Convert Kilometres to Miles
6 Flow of Control Using If Statements
6.1 Introduction
6.2 Comparison Operators
6.3 Logical Operators
6.4 The If Statement
6.4.1 Working with an If Statement
6.4.2 Else in an If Statement
6.4.3 The Use of elif
6.5 Nesting If Statements
6.6 If Expressions
6.7 A Note on True and False
6.8 Hints
6.9 Online Resources
6.10 Exercises
6.10.1 Check Input Is Positive or Negative
6.10.2 Test if a Number Is Odd or Even
6.10.3 Kilometres to Miles Converter
7 Iteration/Looping
7.1 Introduction
7.2 While Loop
7.3 For Loop
7.4 Break Loop Statement
7.5 Continue Loop Statement
7.6 For Loop with Else
7.7 A Note on Loop Variable Naming
7.8 Dice Roll Game
7.9 Online Resources
7.10 Exercises
7.10.1 Calculate the Factorial of a Number
7.10.2 Print All the Prime Numbers in a Range
8 Number Guessing Game
8.1 Introduction
8.2 Setting Up the Program
8.2.1 Add a Welcome Message
8.2.2 Running the Program
8.3 What Will the Program Do?
8.4 Creating the Game
8.4.1 Generate the Random Number
8.4.2 Obtain an Input from the User
8.4.3 Check to See If the Player Has Guessed the Number
8.4.4 Check They Havenβt Exceeded Their Maximum Number of Guess
8.4.5 Notify the Player Whether Higher or Lower
8.4.6 End of Game Status
8.5 The Complete Listing
8.6 Hints
8.6.1 Initialising Variables
8.6.2 Blank Lines Within a Block of Code
8.7 Exercises
9 Recursion
9.1 Introduction
9.2 Recursive Behaviour
9.3 Benefits of Recursion
9.4 Recursively Searching a Tree
9.5 Recursion in Python
9.6 Calculating Factorial Recursively
9.7 Disadvantages of Recursion
9.8 Online Resources
9.9 Exercises
10 Introduction to Structured Analysis
10.1 Introduction
10.2 Structured Analysis and Function Identification
10.3 Functional Decomposition
10.3.1 Functional Decomposition Terminology
10.3.2 Functional Decomposition Process
10.3.3 Calculator Functional Decomposition Example
10.4 Functional Flow
10.5 Data Flow Diagrams
10.6 Flowcharts
10.7 Data Dictionary
10.8 Online Resources
11 Functions in Python
11.1 Introduction
11.2 What Are Functions?
11.3 How Functions Work
11.4 Types of Functions
11.5 Defining Functions
11.5.1 An Example Function
11.6 Returning Values from Functions
11.7 Docstring
11.8 Function Parameters
11.8.1 Multiple Parameter Functions
11.8.2 Default Parameter Values
11.8.3 Named Arguments
11.8.4 Arbitrary Arguments
11.8.5 Positional and Keyword Arguments
11.9 Anonymous Functions
11.10 Online Resources
11.11 Exercises
12 Scope and Lifetime of Variables
12.1 Introduction
12.2 Local Variables
12.3 The Global Keyword
12.4 Nonlocal Variables
12.5 Hints
12.6 Online Resources
12.7 Exercise
13 Implementing a Calculator Using Functions
13.1 Introduction
13.2 What the Calculator Will Do
13.3 Getting Started
13.4 The Calculator Operations
13.5 Behaviour of the Calculator
13.6 Identifying Whether the User Has Finished
13.7 Selecting the Operation
13.8 Obtaining the Input Numbers
13.9 Determining the Operation to Execute
13.10 Running the Calculator
13.11 Exercises
14 Introduction to Functional Programming
14.1 Introduction
14.2 What Is Functional Programming?
14.3 Advantages to Functional Programming
14.4 Disadvantages of Functional Programming
14.5 Referential Transparency
14.6 Further Reading
15 Higher Order Functions
15.1 Introduction
15.2 Recap on Functions in Python
15.3 Functions as Objects
15.4 Higher Order Function Concepts
15.4.1 Higher Order Function Example
15.5 Python Higher Order Functions
15.5.1 Using Higher Order Functions
15.5.2 Functions Returning Functions
15.6 Online Resources
15.7 Exercises
16 Curried Functions
16.1 Introduction
16.2 Currying Concepts
16.3 Python and Curried Functions
16.4 Closures
16.5 Online Resources
16.6 Exercises
17 Introduction to Object Orientation
17.1 Introduction
17.2 Classes
17.3 What Are Classes for?
17.3.1 What Should a Class Do?
17.3.2 Class Terminology
17.4 How Is an OO System Constructed?
17.4.1 Where Do We Start?
17.4.2 Identifying the Objects
17.4.3 Identifying the Services or Methods
17.4.4 Refining the Objects
17.4.5 Bringing It All Together
17.5 Where Is the Structure in an OO Program?
17.6 Further Reading
18 Python Classes
18.1 Introduction
18.2 Class Definitions
18.3 Creating Examples of the Class Person
18.4 Be Careful with Assignment
18.5 Printing Out Objects
18.5.1 Accessing Object Attributes
18.5.2 Defining a Default String Representation
18.6 Providing a Class Comment
18.7 Adding a Birthday Method
18.8 Defining Instance Methods
18.9 Person Class Recap
18.10 The del Keyword
18.11 Automatic Memory Management
18.12 Intrinsic Attributes
18.13 Online Resources
18.14 Exercises
19 Class Side and Static Behaviour
19.1 Introduction
19.2 Class Side Data
19.3 Class Side Methods
19.3.1 Why Class-Side Methods?
19.4 Static Methods
19.5 Hints
19.6 Online Resources
19.7 Exercises
20 Class Inheritance
20.1 Introduction
20.2 What Is Inheritance?
20.3 Terminology Around Inheritance
20.4 The Class Object and Inheritance
20.5 The Built-in Object Class
20.6 Purpose of Subclasses
20.7 Overriding Methods
20.8 Extending Superclass Methods
20.9 Inheritance Oriented Naming Conventions
20.10 Python and Multiple Inheritance
20.11 Multiple Inheritance Considered Harmful
20.12 Summary
20.13 Online Resources
20.14 Exercises
21 Why Bother with Object Orientation?
21.1 Introduction
21.2 The Procedural Approach
21.2.1 Procedures for the Data Structure
21.2.2 Packages
21.3 Does Object Orientation Do Any Better?
21.3.1 Packages Versus Classes
21.3.2 Inheritance
21.4 Summary
22 Operator Overloading
22.1 Introduction
22.2 Operator Overloading
22.2.1 Why Have Operator Overloading?
22.2.2 Why Not Have Operator Overloading?
22.2.3 Implementing Operator Overloading
22.3 Numerical Operators
22.4 Comparison Operators
22.5 Logical Operators
22.6 Summary
22.7 Online Resources
22.8 Exercises
23 Python Properties
23.1 Introduction
23.2 Python Attributes
23.3 Setter and Getter Style Methods
23.4 Public Interface to Properties
23.5 More Concise Property Definitions
23.6 Online Resources
23.7 Exercises
24 Error and Exception Handling
24.1 Introduction
24.2 Errors and Exceptions
24.3 What Is an Exception?
24.4 What Is Exception Handling?
24.5 Handling an Exception
24.5.1 Accessing the Exception Object
24.5.2 Jumping to Exception Handlers
24.5.3 Catch Any Exception
24.5.4 The Else Clause
24.5.5 The Finally Clause
24.6 Raising an Exception
24.7 Defining an Custom Exception
24.8 Chaining Exceptions
24.9 Online Resources
24.10 Exercises
25 Python Modules and Packages
25.1 Introduction
25.2 Modules
25.3 Python Modules
25.4 Importing Python Modules
25.4.1 Importing a Module
25.4.2 Importing from a Module
25.4.3 Hiding Some Elements of a Module
25.4.4 Importing Within a Function
25.5 Module Properties
25.6 Standard Modules
25.7 Python Module Search Path
25.8 Modules as Scripts
25.9 Python Packages
25.9.1 Package Organisation
25.9.2 Sub Packages
25.10 Online Resources
25.11 Exercise
26 Abstract Base Classes
26.1 Introduction
26.2 Abstract Classes as a Concept
26.3 Abstract Base Classes in Python
26.3.1 Subclassing an ABC
26.3.2 Defining an Abstract Base Class
26.4 Defining an Interface
26.5 Virtual Subclasses
26.6 Mixins
26.7 Online Resources
26.8 Exercises
27 Protocols, Polymorphism and Descriptors
27.1 Introduction
27.2 Implicit Contracts
27.3 Duck Typing
27.4 Protocols
27.5 An Protocol Example
27.6 The Context Manager Protocol
27.7 Polymorphism
27.8 The Descriptor Protocol
27.9 Online Resources
27.10 Exercises
28 Monkey Patching and Attribute Lookup
28.1 Introduction
28.2 What Is Monkey Patching?
28.2.1 How Does Monkey Patching Work?
28.2.2 Monkey Patching Example
28.2.3 The Self Parameter
28.2.4 Adding New Data to a Class
28.3 Attribute Lookup
28.4 Handling Unknown Attribute Access
28.5 Handling Unknown Method Invocations
28.6 Intercepting Attribute Lookup
28.7 Intercepting Setting an Attribute
28.8 Online Resources
28.9 Exercises
29 Decorators
29.1 Introduction
29.2 What Are Decorators?
29.3 Defining a Decorator
29.4 Using Decorators
29.5 Functions with Parameters
29.6 Stacked Decorators
29.7 Parameterised Decorators
29.8 Method Decorators
29.8.1 Methods Without Parameters
29.8.2 Methods with Parameters
29.9 Class Decorators
29.10 When Is a Decorator Executed?
29.11 Built-in Decorators
29.12 FuncTools Wrap
29.13 Online Resources
29.14 Book Reference
29.15 Exercises
30 Iterables, Iterators, Generators and Coroutines
30.1 Introduction
30.2 Iteration
30.2.1 Iterables
30.2.2 Iterators
30.2.3 The Iteration Related Methods
30.2.4 The Iterable Evens Class
30.2.5 Using the Evens Class with a for Loop
30.3 The Itertools Module
30.4 Generators
30.4.1 Defining a Generator Function
30.4.2 Using a Generator Function in a for Loop
30.4.3 When Do the Yield Statements Execute?
30.4.4 An Even Number Generator
30.4.5 Nesting Generator Functions
30.4.6 Using Generators Outside a for Loop
30.5 Coroutines
30.6 Online Resources
30.7 Exercises
31 Collections, Tuples and Lists
31.1 Introduction
31.2 Python Collection Types
31.3 Tuples
31.3.1 Creating Tuples
31.3.2 The tuple() Constructor Function
31.3.3 Accessing Elements of a Tuple
31.3.4 Creating New Tuples from Existing Tuples
31.3.5 Tuples Can Hold Different Types
31.3.6 Iterating Over Tuples
31.3.7 Tuple Related Functions
31.3.8 Checking if an Element Exists
31.3.9 Nested Tuples
31.3.10 Things You Canβt Do with Tuples
31.4 Lists
31.4.1 Creating Lists
31.4.2 List Constructor Function
31.4.3 Accessing Elements from a List
31.4.4 Adding to a List
31.4.5 Inserting into a List
31.4.6 List Concatenation
31.4.7 Removing from a List
31.4.8 The pop() Method
31.4.9 Deleting from a List
31.4.10 List Methods
31.5 Online Resources
31.6 Exercises
32 Sets
32.1 Introduction
32.2 Creating a Set
32.3 The Set() Constructor Function
32.4 Accessing Elements in a Set
32.5 Working with Sets
32.5.1 Checking for Presence of an Element
32.5.2 Adding Items to a Set
32.5.3 Changing Items in a Set
32.5.4 Obtaining the Length of a Set
32.5.5 Obtaining the Max and Min Values in a Set
32.5.6 Removing an Item
32.5.7 Nesting Sets
32.6 Set Operations
32.7 Set Methods
32.8 Online Resources
32.9 Exercises
33 Dictionaries
33.1 Introduction
33.2 Creating a Dictionary
33.2.1 The dict() Constructor Function
33.3 Working with Dictionaries
33.3.1 Accessing Items via Keys
33.3.2 Adding a New Entry
33.3.3 Changing a Keys Value
33.3.4 Removing an Entry
33.3.5 Iterating over Keys
33.3.6 Values, Keys and Items
33.3.7 Checking Key Membership
33.3.8 Obtaining the Length of a Dictionary
33.3.9 Nesting Dictionaries
33.4 A Note on Dictionary Key Objects
33.5 Dictionary Methods
33.6 Online Resources
33.7 Exercises
34 Collection Related Modules
34.1 Introduction
34.2 List Comprehension
34.3 The Collections Module
34.4 The Itertools Module
34.5 Online Resources
34.6 Exercises
35 ADTs, Queues and Stacks
35.1 Introduction
35.2 Abstract Data Types
35.3 Data Structures
35.4 Queues
35.4.1 Python List as a Queue
35.4.2 Defining a Queue Class
35.5 Stacks
35.5.1 Python List as a Stack
35.6 Online Resources
35.7 Exercises
36 Map, Filter and Reduce
36.1 Introduction
36.2 Filter
36.3 Map
36.4 Reduce
36.5 Online Resources
36.6 Exercises
37 TicTacToe Game
37.1 Introduction
37.2 Classes in the Game
37.3 Counter Class
37.4 Move Class
37.5 The Player Class
37.6 The HumanPlayer Class
37.7 The ComputerPlayer Class
37.8 The Board Class
37.9 The Game Class
37.10 Running the Game
π SIMILAR VOLUMES
This textbook on Python 3 explains concepts such as variables and what they represent, how data is held in memory, how a for loop works and what a string is. It also introduces key concepts such as functions, modules and packages as well as object orientation and functional programming. Each section
This textbook on Python 3 explains concepts such as variables and what they represent, how data is held in memory, how a for loop works and what a string is. It also introduces key concepts such as functions, modules and packages as well as object orientation and functional programming. Each section
This textbook on Python 3 explains concepts such as variables and what they represent, how data is held in memory, how a for loop works and what a string is. It also introduces key concepts such as functions, modules and packages as well as object orientation and functional programming. Each section