Ganesh Pal <ganesh1...@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

-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to