Print out a date, given year, month, and day as numbers : Assignment « List « Python Tutorial






months = [
    'January',
    'February',
    'March',
    'April',
    'May',
    'June',
    'July',
    'August',
    'September',
    'October',
    'November',
    'December'
]

# A list with one ending for each number from 1 to 31
endings = ['st', 'nd', 'rd'] + 17 * ['th'] \
        + ['st', 'nd', 'rd'] +  7 * ['th'] \
        + ['st']

month_number = 8
day_number = 1

month_name = months[month_number-1]
ordinal = endings[day_number-1]

print month_name 
print ordinal








7.3.Assignment
7.3.1.Changing Lists: Item Assignments
7.3.2.Assigning to Slices
7.3.3.Replace the slice with a sequence whose length is different from that of the original
7.3.4.Slice assignments can even be used to insert elements without replacing any of the original ones
7.3.5.You can do the reverse to delete a slice
7.3.6.Print out a date, given year, month, and day as numbers