擅长:python、mysql、java
<p>您可以让Python将每个元组中的两个值解压为易于使用的变量,如下所示:</p>
<pre><code>vacc_counties = [('Pulaski', 42.7), ('Benton', 41.4), ('Fulton', 22.1), ('Miller', 9.6),
('Mississippi', 29.4), ('Scotty County', 28.1)]
for county, rate in vacc_counties:
if int(rate) > 30:
print(f"{county} has a higher that 30% vaccination rate")
print()
for county, rate in vacc_counties:
if int(rate) > 30:
print(f"{county} is doing ok, with a rate of {rate}%")
else:
print(f"{county} is doing less ok, with a rate of {rate}%")
</code></pre>