在 python 列表中,每个元素有两个项目,第一个是 str,第二个是 float
L= [('A', Decimal('52.00')), ('B', Decimal('87.80')), ('G', Decimal('32.50'))]
Run Code Online (Sandbox Code Playgroud)
for loop我想在元素中使用两个项目
NewL= []
for row in L:
### do something with str
InSql= "SELECT " % str
f= csr.execute(InSql)
ns = list(f)
###do something with float
InSql= "SELECT " % float
f= csr.execute(InSql)
nf = list(f)
NewL.append(str, float,ns, nf)
Run Code Online (Sandbox Code Playgroud)
将循环更改for为如下所示:
for str_data, float_data in L:
# str_data is the string, float_data is the Decimal object
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
843 次 |
| 最近记录: |