0

Sorry for the title it's hard to explain. This code is pretty self-explanatory for what I'm trying to accomplish. Thanks for any help!

handtype = ""
hand_format = 'Handtype: %s' % (handtype)
if y:
    handtype = "Straight"
    hand = hand_format

hand

Desired Output = 'Handtype: Straight'

1

2 Answers 2

1

A simple approach would be to access the value by defining a function instead. Something like this:-

handtype = ""
hand_format = lambda : f"Handtype : {handtype}"
if y:
    handtype = "Straight"
    hand = hand_format()

hand

Whenever you will call hand_format, you will access the latest value.

Sign up to request clarification or add additional context in comments.

1 Comment

This is the answer. Thanks!
0

The hand_format is created once, and by changing the handtype , it does not change.

Only the string format should be saved in the hand_format variable.

You have to do this :

handtype = ""
hand_format = 'Handtype: %s' 
if y:
    handtype = "Straight"
    hand = hand_format % (handtype)

hand

If we print hand

Handtype: Straight

1 Comment

This is exactly what I was trying to avoid doing. But perhaps there is no way around it. Thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.