How can I make a function that takes the month and returns the first two characters?
def abbreviation():
Should I use len?
>>> abbreviation( 'March')
'Ma'
How can I print it out like this?
python
No matter what value comes in, should I return the first two letters?
def abbreviation(month):
return month[:2]
>>> abbreviation('March')
'Ma'
You can do it like above.
If you want to return the first two characters only if the input value is one of January through December, try putting in a few conditional statements.
© 2024 OneMinuteCode. All rights reserved.