Skip to main content
Ctrl+K
Introduction to Computer Science in Python: Principles and Practice (07 May 2026) - Home Introduction to Computer Science in Python: Principles and Practice (07 May 2026) - Home
  • Introduction to Computer Science in Python
  • Context
    • Motivation for This Book
    • Resources Online
    • Computer Science, Broadly
    • Chapter Review Questions
  • Python Data and Operations
    • A Sample Python Program
    • Lab: Editing and Running Python Programs
    • Arithmetic
    • Variables and Assignment
    • Reading Python Syntax
    • Strings, Part I
    • Writing to the Screen
    • Python Program Structure
    • Combining Input and Output
    • String Special Cases
    • F-Strings and String Formatting
    • Types and Conversions
    • Learning to Solve Problems
    • Lab: Division Sentences
    • Chapter Review Questions
  • Defining Functions of Your Own
    • A First Function Definition
    • Multiple Function Definitions
    • Function Parameters
    • Multiple Function Parameters
    • Returned Function Values
    • Two Roles: Writer and Consumer of Functions
    • Local Scope
    • Library Modules
    • Chapter Review Questions
  • Basic String Operations
    • String Indexing and Slicing
    • String Methods and Length
    • A Creative Problem Solution
    • Lab: String Operations
    • Chapter Review Questions
  • Decisions
    • Conditions
    • More Conditional Expressions
    • Compound Boolean Expressions
    • Simple if Statements
    • if-elif-else Statements
    • Nested if Statements
    • If-Statement Pitfalls
    • Chapter Review Questions
  • While Loops
    • While Statements
    • User Input Utilities
    • Interactive while Loops
    • While Loops with Sequences
    • While Loop Examples
    • Greatest Common Divisor
    • Lab: Number Guessing Game
    • Chapter Review Questions
  • For Loops
    • For Loop Syntax
    • The range() Function
    • For Loop Examples
    • List Comprehensions
    • Lab: Nested Loops
    • Chapter Review Questions
  • Files, Paths, and Directories
    • Path Strings
    • Reading Files
    • Writing Files
    • Working with pathlib
    • Chapter Review Questions
  • Lists
    • List Syntax
    • List Methods
    • Searching
    • Sorting
    • Lab: Lists
    • Chapter Review Questions
  • Tuples
    • Tuple Syntax
    • Tuple Examples
    • Tuple Unpacking
    • Chapter Review Questions
  • Dictionaries
    • Dictionary Syntax
    • Dictionary Examples
    • Dictionary Efficiency
    • Lab: File Data and Collections
    • Chapter Review Questions
  • Classes and Object-Oriented Programming
    • A First Example of Class Instances
    • Class Instance Examples
    • Planning a Class Structure
    • Python Dataclasses
    • The Rational Class
    • Chapter Review Questions
  • Testing
    • Introduction to pytest
    • Writing Effective Tests
    • Chapter Review Questions
  • Recursion
    • Introduction to Recursion
    • Recursion Examples
    • Chapter Review Questions
  • Data Structures
    • Stacks and Queues
    • Linked Lists
    • Chapter Review Questions
  • Appendix
    • Contributors
    • Acknowledgments
    • Command Line Introduction
    • Operator Precedence
    • Homework: Grade Calculation
    • Lab: Version Control
  • Repository
  • Open issue

Defining Functions of Your Own

Defining Functions of Your Own#

  • A First Function Definition
    • The Birthday Problem
    • Defining a Function
    • Calling a Function
    • Calling Multiple Times
  • Multiple Function Definitions
    • Example: Two Birthday Songs
    • Order of Definitions and Calls
  • Function Parameters
    • Defining a Parameter
    • Calling with an Argument
    • How it Works
    • Parameters vs. Arguments
  • Multiple Function Parameters
    • Example: Addition
    • Keyword Arguments
    • Default Values
  • Returned Function Values
    • The return Statement
    • Example: Weekly Wages
    • Functions Without return
    • Early Return
  • Two Roles: Writer and Consumer of Functions
    • The Writer
    • The Consumer
    • The Contract
    • Separation of Concerns
  • Local Scope
    • Local Variables
    • Why Local Scope?
    • How Python Looks Up Names
    • Using Global Variables (Avoid When Possible)
    • Bad Scope Example
  • Library Modules
    • Importing a Module
    • The math Module
    • The random Module
    • Selective Import
    • How Python Finds Modules
    • Writing Your Own Module
  • Chapter Review Questions

previous

Chapter Review Questions

next

A First Function Definition

By The Computer Science Department Faculty at Loyola University Chicago

© Copyright 2025, The Computer Science Department Faculty at Loyola University Chicago.

Last updated on 07-May-2026 04:05:09.