Month Names

In [5]:
def main():
    months = "JanFebMarAprMayJunJulAugSepOctNovDec"
    n = int(input("Enter a month number (1-12): "))
    
    pos = (n - 1) * 3
    month_abbrev = months[pos:pos+3]
    
    print("The month abbrev is", month_abbrev )
In [6]:
main()
Enter a month number (1-12): 7
The month abbrev is Jul
In [7]:
main()
Enter a month number (1-12): 9
The month abbrev is Sep
In [8]:
def months2():
    months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
              "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
    
    n = int(input("Enter a month number (1-12): "))
    
    month_abbrev = months[n - 1]
    
    print("The month abbrev is", month_abbrev )
In [9]:
months2()
Enter a month number (1-12): 7
The month abbrev is Jul

Makings Lists

In [10]:
list1 = list()
In [11]:
list2 = []
In [12]:
print(list1, list2)
[] []
In [14]:
list3 = ['Jan', 'Feb', ['Kirk', 'Spock', 'McCoy']]
In [15]:
list3
Out[15]:
['Jan', 'Feb', ['Kirk', 'Spock', 'McCoy']]
In [19]:
list3[2][-1]
Out[19]:
'McCoy'