# Hi am leaning python with A Byte of Python - Swaroop CH and am a little confused with The format method. So I leaned that printing the code:
>>>age = 20
>>>name = 'Swaroop'
>>>print '{0} was {1} years old when he wrote this book'.format(name, age)
>>>print 'Why is {0} playing with that python?'.format(name)
# I no that the code will give you the same output even without numbers:
Swaroop was 20 years old when he wrote this book
Why is Swaroop playing with that python?
#Am having little trouble trying to understand this part of the code:
# decimal (.) precision of 3 for float '0.333'
>>>print '{0:.3f}'.format(1.0/3)
# fill with underscores (_) with the text centered
# (^) to 11 width '___hello___'
>>>print '{0:_^11}'.format('hello')
# keyword-based 'Swaroop wrote A Byte of Python'
>>>print '{name} wrote {book}'.format(name='Swaroop',
book='A Byte of Python')
# Line 1: I know the first line has the out put of 0.333 because 1.0 is divided by 3.
# Line 2: why is the output: ___hello___ and not just hello?
#what does {0:_^11} mean?
#any other information you may have, please share with me._______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor