class Beers:
def __init__(beer, name):
beer.name = name
def beer_data(beer, type, price, size, packs):
beer.type = type
beer.price = price
beer.size = size
beer.packs = packs
def beer_additional_data(beer):
beer.data_List = []
beer.data_List += beer.name, beer.size*beer.packs
hjnakken = Beers('Hjnakken')
bidwsr = Beers('Bidwsr')
cirona = Beers('Cirona')
hjnakken.beer_data('Pale lager', 2.3, 6, 12)
bidwsr.beer_data('American lager', 2.0, 8, 10)
cirona.beer_data('Pale lager', 2.6, 8, 6)
hjnakken.beer_additional_data()
bidwsr.beer_additional_data()
cirona.beer_additional_data()
which_beer = input('Enter beer name: ')
在没有if语句的情况下如何执行此操作(如下)? pythonic的方式是什么?
print(which_beer.data_List)
我想在用户输入后得到XYZ.data_List
。
beer.name
匹配)XYZ.data_List