开发者

Use 1 out of 2 returned values as string

开发者 https://www.devze.com 2023-02-10 11:35 出处:网络
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:
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

精彩评论

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

关注公众号