GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Python tutorial could make rules for default argument definition clearer · Issue #87209 · python/cpython

Python tutorial could make rules for default argument definition clearer #87209

New issue
Copy link
New issue
Copy link
Open
#138529
Open
Python tutorial could make rules for default argument definition clearer#87209
#138529
Copy link
Labels
docsDocumentation in the Doc dirDocumentation in the Doc direasy

Description

jessevsilverman
mannequin
opened on Jan 27, 2021
Issue body actions
BPO 43043

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2021-01-27.22:01:00.254>
labels = ['3.9', 'docs']
title = 'Python tutorial could make rules for default argument definition clearer'
updated_at = <Date 2021-01-27.22:01:00.254>
user = 'https://bugs.python.org/jessevsilverman'

bugs.python.org fields:

activity = <Date 2021-01-27.22:01:00.254>
actor = 'jessevsilverman'
assignee = 'docs@python'
closed = False
closed_date = None
closer = None
components = ['Documentation']
creation = <Date 2021-01-27.22:01:00.254>
creator = 'jessevsilverman'
dependencies = []
files = []
hgrepos = []
issue_num = 43043
keywords = []
message_count = 1.0
messages = ['385813']
nosy_count = 2.0
nosy_names = ['docs@python', 'jessevsilverman']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = None
url = 'https://bugs.python.org/issue43043'
versions = ['Python 3.9']

Linked PRs

  • gh-87209: Clarify ordering rule for default arguments in tutorial #138529

Activity

  1. jessevsilverman commented on Jan 27, 2021

    @jessevsilverman
    jessevsilvermanmannequin
    on Jan 27, 2021
    MannequinAuthor
    More actions

    I love the tutorial, but have been pointing out things I only knew from brutal experience, other tutorials, reasoning from other languages I know better, or looking things up. I only mention them if they seem in scope and at the same level of the material which is presented.

    Regarding 4.7.1. Default Argument Values of the excellent Python tutorial:

    I guessed that I would see the behavior shown below from my understanding of default arguments in several other languages. I did not read anything in this tutorial section that would lead me to conclude this, and other things mentioned in this section are neither much more or less subtle, more or less obvious, or more or less important.

    PS F:\\PythonCode\> py VarArgs.py
      File "F:\\PythonCode\\VarArgs.py", line 1
        def varArgs(quote, footnote='', times):
                                             ^
    SyntaxError: non-default argument follows default argument
    

    Most introductions to default argument definition in other languages go out of their way to highlight that the default parameters can be only the last N of them, and that all required ones must come first.
    Python is intended to be accessible to people no more clever than the other languages intend, so tho it seems obvious to me that they must only come after all required arguments, I remember when it was not obvious (and fortunately the tutorials I read in the past for other languages belabored the point).

    The explanatory text of:
    giving one of the optional arguments: ask_ok('OK to overwrite the file?', 2)

    as it merely says "one of", rather than "the first of" led me to wonder if Python was somehow more flexible/better at mind-reading than the languages I already know well that require all default args to be trailing, and to only let you default the last one, two, or ... N. The results of the experiment shown above demonstrate it is similar to the behavior in other languages in this regard.

    I deeply appreciate the information about when the default arguments get evaluated, which is highly relevant and is not something I would have picked up on from other languages I've used.

    A simple line stating that "any default arguments must follow any required arguments in the definition" and something like "on calls, optional arguments may only be omitted from the end of the parameter list, they can't simply be skipped" would be awesome.

    I am not sure whether or not this is made perfectly clear in the next section, which has a lot of other new and interesting ideas flying around in it as well, besides this one.

  2. jessevsilverman
    added
    3.9 (EOL)end of lifeend of life
    on Jan 27, 2021
  3. jessevsilverman
    assigned
    docspython
    on Jan 27, 2021
  4. jessevsilverman
    added
    docsDocumentation in the Doc dirDocumentation in the Doc dir
    3.9 (EOL)end of lifeend of life
    on Jan 27, 2021
  5. jessevsilverman
    assigned
    docspython
    on Jan 27, 2021
  6. jessevsilverman
    added
    docsDocumentation in the Doc dirDocumentation in the Doc dir
    on Jan 27, 2021
  7. ezio-melotti
    transferred this issue fromon Apr 10, 2022
  8. StanFromIreland
    removed
    3.9 (EOL)end of lifeend of life
    on Aug 11, 2025
  9. github-project-automation
    added this to docs issueson Aug 11, 2025
  10. github-project-automation
    moved this to Todo in docs issueson Aug 11, 2025
  11. StanFromIreland
    added
    easy
    on Sep 4, 2025
  12. jeff14994 commented on Sep 5, 2025

    @jeff14994
    jeff14994
    on Sep 5, 2025
    More actions

    Hi, I’d like to work on this issue.

    To address the concern, I propose a small wording change in section [4.9.1. Default Argument Values](https://docs.python.org/3/tutorial/controlflow.html#default-argument-values).

    Current text:

    The most useful form is to specify a default value for one or more arguments. This creates a function that can be called with fewer arguments than it is defined to allow.

    Proposed text:

    The most useful form is to specify a default value for one or more arguments. All arguments without default values must come first, followed by those with defaults. This allows a function to be called with fewer arguments than it is defined to allow.

    Would this wording change be acceptable, or would you prefer a different approach?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dirDocumentation in the Doc direasy

    Projects

    • docs issues
      Status
      Todo
      Show more project fields

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.