开发者

Use 1 out of 2 returned values as string

divmod(X, Y)

returns (A, B)

How would I turn either A or B into a string?

EDIT: to clarify, I'd like to use them 1 at 开发者_开发百科a time :)


If you'd like to randomly select one or the other:

import random
str(random.choice(divmod(X,Y)))


Are you looking for

str(divmod(x, y)[0])

and

str(divmod(x, y)[1])

respectively?

You can also write

a, b = divmod(x, y)
str(a)
str(b)

(Of course you should do something with str(a) instead of simply creating it.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜