What is a real-world (production-code) example of a function having default arguments? I want to teach students about default function arguments.
I have a bad habit of cooking-up contrived examples.
To prove that I am not a student cheating on their homework, I shall provide you with the following code. I really can write an example of a function without default arguments on my own, it is simply too contrived:
class SandwhichMaker:

    FISH = &quot;&quot;&quot;
              /&quot;*._         _
          .-*'`    `*-.._.-'/
        &lt; * ))     ,       ( 
          `*-._`._(__.--*&quot;`.\ 
        
    &quot;&quot;&quot;

    @classmethod
    def publicly_make_sandwhich(klass, bread, veggie, meat = &quot;fish&quot;, sauce = None):
        if (sauce == None):
            sauce = klass.meat_to_sauce(meat)
        bread  = str(bread)
        veggie = str(veggie)
        meat   = str(meat).lower()
        if meat == &quot;fish&quot;:
            meat = SandwhichMaker.FISH
        sandwhich = klass.privatly_make_sandwhich(bread, veggie, meat, sauce)
        return sandwhich

    @classmethod
    def meat_to_sauce(cls, meat):
        if meat.lower() == &quot;fish&quot;:
            return &quot;tartar sauce&quot;

    @classmethod
    def privatly_make_sandwhich(cls, bread, veggie, meat, sauce):
        &quot;&quot;&quot;
        PRECONDITION: all input parameters are strings
        &quot;&quot;&quot;
        seperator = &quot;\n&quot; + 40 * &quot;-&quot; + &quot;\n&quot;
        sandwhich = seperator.join([
            &quot;\n\n&quot;,
            bread,
            veggie,
            meat,
            sauce,
            bread
        ])
        return sandwhich


sw = SandwhichMaker()

sandwhich = sw.publicly_make_sandwhich(&quot;whole wheat&quot;, &quot;cucumber&quot;, &quot;fish&quot;)

print(sandwhich)

Console output:
----------------------------------------
whole wheat
----------------------------------------
cucumber
----------------------------------------

              /&quot;*._         _
          .-*'`    `*-.._.-'/
        &lt; * ))     ,       ( 
          `*-._`._(__.--*&quot;`.\ 
        
    
----------------------------------------
tartar sauce
----------------------------------------
whole wheat

So, my example function with default arguments is as follows:
publicly_make_sandwhich(klass, bread, veggie, meat = &quot;fish&quot;, sauce = None):

The default meat is &quot;fish&quot;
I really want students to see how default arguments can be useful.
I thought about downloading a few open source code repositories.
I could then search all text-files for a regular expression (regex) to find functions having default arguments.
\(\s*\w*\s*\w+\s*=[^),][^)]*\)



Exactly one left parenthesis ... [1, 1] of (
Zero or more of any white-space character ([0, +inf] of \s)
optional data-type such as float or int. zero or more letters, numbers or underscores. [1, +inf] of [a-zA-Z0-9_]
zero or more white-space characters
one or more letters, numbers or underscores.
zero or more white-space chars
exactly one equals sign
exactly one character except right-paren or comma
zero or more character other than right-paren
exactly one right-parenthesis


It would be easier just to ask a human being for a good example.
I recently used default arguments to write an API method for a mail sending library: The method needs a subject, a body and a &quot;To&quot; recipient, &quot;Cc&quot; and &quot;Bcc&quot; are optional:
def send(subject, body, to, cc=None, bcc=None):
    &quot;&quot;&quot;
    Send a message with the given data using the earlier configured SMTP server and the earlier configured from address.
    :param subject: The subject (one-line string)
    :param body: The contents (multiline string)
    :param to: Recipient address (string)
    :param cc: CC address (string or None)
    :param bcc: BCC address (string or None)
    &quot;&quot;&quot;
    # The following to helper functions are omitted for brevity
    msg = _create_message(subject, body, to, cc, bcc)
    _send_message(msg)

I also quite often use this to specify default constructor arguments for machine learning setups, so that I can change the parameters when experimenting, but have a default variant during development:
import random

class MulticlassPerceptron:

   def __init__(self, epochs=100, learning_rate=0.9, random_seed=15):
      self.epochs = epochs
      self.learning_rate = learning_rate
      random.seed(random_seed)
      ...

   def train(self, training_data):
      for epoch in range(self.epochs):
         for datapoint in training_data:
            ...

train_dataset = ...
m = MulticlassPerceptron()
m.train(train_dataset)

Generally, I make quite heavy use of default arguments whenever I write scripts for myself, because for me they are a perfect compromise between those two objectives:

No one else than me will use the scripts, and my configuration is pretty constant, so there is no need for complex Config objects etc.
It is bad practice to hardcode things that are technically changeable parameters.

So what I usually do is write methods that have only default arguments which store my default configuration: This is an easy way to store a configuration (satisfies objective 1) but could be changed if the need ever arises (satisfies objective 2).
Does this help you? If not, I'm happy to add more examples.