Skip to content

print() doesn't accept the double starred expression *v and f-strings doesn't accept the single and double starred expression *v and **v #137799

@hyperkai

Description

@hyperkai

Bug report

Bug description:

print() accepts the single starred expression *v as shown below:

v = ['A', 'B', 'C', 'D', 'E']

print(*v)
# A B C D E

But print() doesn't accept the double starred expression **v as shown below:

v = {'name':'John', 'age':36}

print(**v)
# TypeError: 'name' is an invalid keyword argument for print()

So, print() should accept the double starred expression **v, displaying the output as shown below:

v = {'name':'John', 'age':36}

print(**v)
# name:John age:36

And, f-strings doesn't accept the single and double starred expression *v and **v as shown below:

v = ['A', 'B', 'C', 'D', 'E']

print(f'{*v}')
print(f'{*v=}')
# SyntaxError: can't use starred expression here
v = {'name':'John', 'age':36}

print(f'{**v}')
print(f'{**v=}')
# SyntaxError: f-string: expecting a valid expression after '{'

So, f-strings should accept the single and double starred expression *v and **v, displaying the outputs as shown below:

v = ['A', 'B', 'C', 'D', 'E']

print(f'{*v}')
# A B C D E

print(f'{*v=}')
# *v=A B C D E
v = {'name':'John', 'age':36}

print(f'{**v}')
# name:John age:36

print(f'{**v=}')
# **v=name:John age:36

CPython versions tested on:

3.12

Operating systems tested on:

Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions