Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #73736 > unrolled thread
| Started by | Martin S <shieldfire@gmail.com> |
|---|---|
| First post | 2014-06-29 20:04 +0200 |
| Last post | 2014-06-29 20:04 +0200 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Newbie coding question - format error Martin S <shieldfire@gmail.com> - 2014-06-29 20:04 +0200
| From | Martin S <shieldfire@gmail.com> |
|---|---|
| Date | 2014-06-29 20:04 +0200 |
| Subject | Re: Newbie coding question - format error |
| Message-ID | <mailman.11330.1404065108.18130.python-list@python.org> |
[Multipart message — attachments visible in raw view] — view raw
Thanks for the input. The main thing was that the replacement fields were only valid for their local environment.
/martin
On 29 Jun 2014, Terry Reedy <tjreedy@udel.edu> wrote:
>On 6/29/2014 3:06 AM, Martin S wrote:
>
>A couple of additional notes:
>
>> x=int(input('Enter an integer '))
>> y=int(input('Enter another integer '))
>> z=int(input('Enter a third integer '))
>> formatStr='Integer {0}, {1}, {2}, and the sum is {3}.'
>
>When the replacement fields and arguments are in the same order, the
>indexes are optional. The following works, and might be less confusing.
>
>formatStr = 'Integer {}, {}, {}, and the sum is {}.'
>
>> equations=formatStr.format(x,y,z,x+y+z)
>
>We no longer have a space shortage ;-). The following is easier to
>read.
>
>equations = formatStr.format(x, y, z, x+y+z)
>
>> print(equations)
>
>Compute quotient and remainder with the divmod function.
>
>q, r = divmod(x, y)
>
>Both are computed at once and x // y and x % y just toss the other
>answer. x // y == divmod(x, y)[0], x % y == divmod(x, y)[1]
-- Sent with K-@ Mail - the evolution of emailing.
Back to top | Article view | comp.lang.python
csiph-web