python错误TypeError: integer argument expected, got float解决方法--map()函数用法,帮助文档

一、解决报错

        在python运行出现错误TypeError: integer argument expected, got float。这句话的意思是:期望得到整数类型,但得到的是浮点数。

Bicubic_Img.putpixel((x, y), tuple(tmp))
'报错:TypeError: integer argument expected, got float'
'解决'
Bicubic_Img.putpixel((x, y), tuple(map(int,tmp)))

        所以解决方法就是输入整数类型,但int()函数用于将字符串或数字转换为整型,而不能将序列转成整型。所以这里使用map()函数。         

tmp=[1.1,2.2,3.3]
'''
int(tmp)
报错:TypeError: int() argument must be a string, a bytes-like object or a number, not 'list
'''
tmp=map(int,tmp)
'''
print(tmp)
不显示结果 <map object at 0x000001DA938C3FD0>
'''
print(list(tmp))
'结果:[1, 2, 3]'

二、map()函数的用法

①map()函数的格式是:

map(func, *iterables) 

②使用map进行整数类型转换方法是:

map(int,[1,2])

③输出map()函数运行结果方法是:

print(list(map(int,[1,2.2])))

④map函数的更多使用方法:

         Python的官方帮助文档 https://docs.python.org/2.7/

           在命令行输入help(map)查看

help(map)
'''
help> map
Help on class map in module builtins:

class map(object)
 |  map(func, *iterables) --> map object
 |  
 |  Make an iterator that computes the function using arguments from
 |  each of the iterables.  Stops when the shortest iterable is exhausted.
 |  
 |  Methods defined here:
 |  
 |  __getattribute__(self, name, /)
 |      Return getattr(self, name).
 |  
 |  __iter__(self, /)
 |      Implement iter(self).
 |  
 |  __next__(self, /)
 |      Implement next(self).
 |  
 |  __reduce__(...)
 |      Return state information for pickling.
 |  
 |  ----------------------------------------------------------------------
 |  Static methods defined here:
 |  
 |  __new__(*args, **kwargs) from builtins.type
 |      Create and return a new object.  See help(type) for accurate signature.

'''

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值