Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #111263
| From | Ben Finney <ben+python@benfinney.id.au> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: one command on backslash and space for review |
| Date | 2016-07-11 15:09 +1000 |
| Message-ID | <mailman.178.1468213766.2295.python-list@python.org> (permalink) |
| References | <CACT3xuWi-BTNM2QRe3Gdk4ZyqyFn-m0U-RNPxJXS2sgMd55ciA@mail.gmail.com> <CALwzidk1Z30Q9RiLQgcM50+o_jDx-yVYcB7mnEH2KNfbaCg8zw@mail.gmail.com> <CACT3xuW2xjbApThg59vwSTeiC6fQmF0YjhNteaxWNNBkqoxaeg@mail.gmail.com> <85r3b0vk05.fsf@benfinney.id.au> |
Ganesh Pal <ganesh1pal@gmail.com> writes:
> How will I format number to strings using .format ??
To make best use of ‘str.format’, read its documentation thoroughly
<URL:https://docs.python.org/3/library/string.html#formatstrings>.
To format numbers to strings, you choose which representation you want;
e.g. “decimal integer”. Then, use the appropriate format syntax for that
representation (in that case, the ‘d’ type specifier).
> Example
>
> >>> str(num)
That creates a new string object, by asking the integer object to return
its string representation. That gives you no choice in the
representation, which is the opposite of what you are asking for.
> >>> cmd = "run_parallel -za{} -s 'daemon -cf xyz; sleep 1'".format(str(num))
The ‘{}‘ format string takes all the defaults for that parameter. If you
want to customise the format, choose the specification and put it inside
the ‘{’ and ‘}’ characters.
--
\ “I know when I'm going to die, because my birth certificate has |
`\ an expiration date.” —Steven Wright |
_o__) |
Ben Finney
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: one command on backslash and space for review Ben Finney <ben+python@benfinney.id.au> - 2016-07-11 15:09 +1000
csiph-web