3

When in a python script I write

>>> v = True
>>> str(v).upper()
'TRUE'

can I assume that 'TRUE' will always be the result, or can I have a translation of True in user terminal language (e.g 'WAHR' if user terminal is in German)?

Bram Vanroy
  • 27,032
  • 24
  • 137
  • 239
  • Yes, it will always give the same result – Davichete Sep 03 '19 at 10:01
  • 1
    Just to preempt what might be a horrid use case, if you're going to write `if str(v).upper() == 'TRUE':` , Please don't. you can directly check the truthiness of the boolean. (`if v:`) – Paritosh Singh Sep 03 '19 at 10:04
  • @Paritosh Singh don't worry, I want to generate a file and be sure that the file only contains "TRUE" or "FALSE" for booleans value –  Sep 03 '19 at 10:15

2 Answers2

2

It will always be TRUE, but if you want to hardcode it yourself:

print( 'TRUE' if v else 'FALSE' )
tituszban
  • 4,797
  • 2
  • 19
  • 30
1

str will give the same result for a boolean regardless of the user terminal language

J Delaney
  • 589
  • 4
  • 17