パディングを使用して複数の変数/テキストを揃えることができました。しかし、私のコードでは、リスト内の変数を変更する必要があるため、長さが変わり、列の配置に影響します。変更する変数の列の整列
product_names = ["hamburger", "cheeseburger", "small fries"]
product_costs = [0.99, 1.29, 1.49]
product_quantity = [10,5,20]
print(format("Product",'<10s'),"Price","Quantity",sep = '\t')
for x in range(len(product_names)):
print(format(product_names[x],'<16s'),end ='')
print(product_costs[x],product_quantity[x],sep = '\t')
私が手出力は次のようになります。私は長いものにチーズバーガーを変更した場合
Product Price Quantity
hamburger 0.99 10
cheeseburger 1.29 5
small fries 1.49 20
けど。例えばダブルチーズバーガー。病気。
Product Price Quantity
hamburger 0.99 10
double cheeseburger1.29 5
small fries 1.49 20
どのように私は私の列が一貫しておくのですか?
あなたは良い推測をするか、最長の名前を取得して使用する必要があります – user1767754