Skip to content

Instantly share code, notes, and snippets.

@NirantK
Last active August 28, 2020 07:57
Show Gist options
  • Save NirantK/c20e7b2e3cc302a967171c327089a5db to your computer and use it in GitHub Desktop.
Save NirantK/c20e7b2e3cc302a967171c327089a5db to your computer and use it in GitHub Desktop.
f string Spacing Demo
correct = 'correct'
phonetic_correct = 'phonetic_correct'
typo = 'typo'
phonetic_typo = 'phonetic_typo'
phonetic_distance = 'phonetic_distance'
print(f'No Spacing:')
print(f'{correct}|{phonetic_correct}|{typo}|{phonetic_typo}|{phonetic_distance}|\n')
# No Spacing:
# correct|phonetic_correct|typo|phonetic_typo|phonetic_distance|
print(f'Right Aligned:')
print(f'{correct:>10}|{phonetic_correct:>20}|{typo:>10}|{phonetic_typo:>20}|{phonetic_distance:>20}|\n')
# Right Aligned:
# correct| phonetic_correct| typo| phonetic_typo| phonetic_distance|
print(f'Left Aligned:')
print(f'{correct:<10}|{phonetic_correct:<20}|{typo:<10}|{phonetic_typo:<20}|{phonetic_distance:<20}|\n')
# Left Aligned:
# correct |phonetic_correct |typo |phonetic_typo |phonetic_distance |
print(f'Centre Aligned:')
print(f'{correct:^10}|{phonetic_correct:^20}|{typo:^10}|{phonetic_typo:^20}|{phonetic_distance:^20}|')
# Centre Aligned:
# correct | phonetic_correct | typo | phonetic_typo | phonetic_distance |
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment