Format Ordinal

Convert a number to its ordinal form (1st, 2nd, 3rd, etc.).

Code

Utilities
suffixes = ['th', 'st', 'nd', 'rd'] + ['th'] * 6
v = num % 100
suffix = suffixes[v - 20] if 20 < v < 30 else suffixes[min(v, 4)]
return f'{num}{suffix}'

Parameters

Number to convert.

Server

More Python Snippets