0

Please explain string formatting for the below code?

https://code.sololearn.com/c7qF7DAHIT3W/?ref=app format_string = '{:25} {:>6} {:19} {:19} {}' print(format_string.format('User', 'Logins', 'Last Login', 'Expires', 'Description')) please explain above two lines and what is the use of :25,:>6,:19 and thank you in advance

22nd Aug 2018, 8:59 PM
Raj Charan
2 Réponses
+ 7
{} is used as a placeholder for the arguments of the format function. The contents in it states modifiers. {:25} takes 'User' and makes it take a minimum 25 spaces. {:19} gets 19 spaces for 'Last Login' & 'Expires'. The > is right aligned so {:>6} puts 'Logins' right aligned in 6 spaces. Note: 'My Logins' would use 9 spaces. For more examples, see this: https://www.geeksforgeeks.org/JUMP_LINK__&&__python__&&__JUMP_LINK-format-function/
23rd Aug 2018, 2:20 AM
John Wells
John Wells - avatar
+ 2
thank you John Wells
23rd Aug 2018, 3:36 AM
Raj Charan