Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-110383: Fix problems in Python Input and Output tutorial#118970

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
uatach wants to merge2 commits intopython:mainfromuatach:problems-io-tutorial
Closed
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletionDoc/tutorial/inputoutput.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -44,6 +44,8 @@ printing space-separated values. There are several ways to format output.
>>> yes_votes = 42_572_654
>>> no_votes = 43_132_495
>>> percentage = yes_votes / (yes_votes + no_votes)
>>> # Print yes_votes padded with spaces and a negative sign only for negative numbers
>>> # Also print percentage multiplied by 100, with 2 decimal places and followed by a percent sign:
>>> '{:-9} YES votes {:2.2%}'.format(yes_votes, percentage)
' 42572654 YES votes 49.67%'

Expand DownExpand Up@@ -197,7 +199,12 @@ notation. ::
Jack: 4098; Sjoerd: 4127; Dcab: 8637678

This is particularly useful in combination with the built-in function
:func:`vars`, which returns a dictionary containing all local variables.
:func:`vars`, which returns a dictionary containing all local variables. ::

>>> table = {k: str(v) for k, v in vars().items()}
>>> message = " ".join([f'{k}: ' + '{' + k +'};' for k in table.keys()])
>>> print(message.format(**table))
__name__: __main__; __doc__: None; __package__: None; __loader__: <class '_frozen_importlib.BuiltinImporter'>; __spec__: None; __annotations__: {}; __builtins__: <module 'builtins' (built-in)>;

As an example, the following lines produce a tidily aligned
set of columns giving integers and their squares and cubes::
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp