Different Ways to Format and Print Characters in Python
1. Using f-strings (Python 3.6+)
print(f'[{chr(65)}]')
[A]
2. Using str.format method
print('[{}]'.format(chr(65)))
[A]
3. Using format function with placeholders
print('[{:c}]'.format(65))
[A]
4. Using concatenation with chr function
print('[' + chr(65) + ']')
[A]
5. Using old-style string formatting
print('[%c]' % 65)
[A]
0 Comments:
Post a Comment