Discuss / Python / 为何我的结果是这个?

为何我的结果是这个?

Topic source

雷小呈

#1 Created at ... [Delete] [Delete and Lock User]

L2 = [x.lower for x in L1 if isinstance(x,str)] print(L2)

为何我的结果是这个?

[<built-in method lower of str object at 0x0000000D0CF6C928>, <built-in method lower of str object at 0x0000000D0CF6C8B8>, <built-in method lower of str object at 0x0000000D0CF6CA40>]

廖雪峰

#2 Created at ... [Delete] [Delete and Lock User]

注意区分方法和方法调用

诏屎孤儿

#3 Created at ... [Delete] [Delete and Lock User]

伙子 你写的是s.lower 是字符串类型的方法lower s.lower()才算调用了lower的方法。


  • 1

Reply