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
2 Answers
+ 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/
+ 2
thank you John Wells