what's the function of tag '#' while using python string format option -


i using python string format option, , after reading document, still confused '#' cause don't know meaning of phrase 'the value conversion use “alternate form” (where defined below).'. great helps me.

here test:

print '%#sabc' % 'abc'  

'abcabc'

print '%#fabc' % 1.2 

1.200000abc

that great if there examples of usage of '#' here.

the "alternative form" changes behavior of selected conversion slightly.

your example floating point representation:

'f': floating point decimal format.

>>> print("%.0f" % 1) 1 

the alternate form causes result contain decimal point, if no digits follow it.

>>> print("%#.0f" % 1) 1. 

example hexadecimal representation:

'x': signed hexadecimal (lowercase).

>>> print("%x" % -11) -b 

the alternate form causes leading '0x' [...] inserted before first digit.

>>> print("%#x" % -11) -0xb 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -