把美国州名String转换成2大写字母列表

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# input
input_str = 'ak,ar,az,ca,ma'
# 可以先转换成大写字母,然后split by ','
output = input_str.upper().split(',')
# output
print(output)
# input input_str = 'ak,ar,az,ca,ma' # 可以先转换成大写字母,然后split by ',' output = input_str.upper().split(',') # output print(output)
# input
input_str = 'ak,ar,az,ca,ma'

# 可以先转换成大写字母,然后split by ','
output = input_str.upper().split(',')

# output
print(output)
['AK', 'AR', 'AZ', 'CA', 'MA']

Reference

Python String upper()

Leave a Comment

Your email address will not be published.