ฟังก์ชัน Built in List ทำไมถึง error ที่ print(cmp(list1, list2))

ตอบกระทู้

รูปแสดงอารมณ์
:icon_plusone: :like: :plusone: :gfb: :-D :) :( :-o 8O :? 8) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: :angry: :baa: :biggrin:
รูปแสดงอารมณ์อื่นๆ

BBCode เปิด
[img] เปิด
[url] เปิด
[Smile icon] เปิด

กระทู้แนะนำ
   

มุมมองที่ขยายได้ กระทู้แนะนำ: ฟังก์ชัน Built in List ทำไมถึง error ที่ print(cmp(list1, list2))

Re: ฟังก์ชัน Built in List ทำไมถึง error ที่ print(cmp(list1, list2))

โดย tatiya » 19/06/2019 6:50 pm

built-in function นี้มันสามารถใช้ได้แค่ใน python 2 ครับ คุณน่าจะใช้ python3.x ใช่มั้ยครับ

หรือจะทำ function ขึ้นมาเอง จะประมาณนี้

โค้ด: เลือกทั้งหมด

list1 =["python", "helloworld", 2013,2024,3]
list2=[1,2,3,4,5,6]


def cmp(a, b):
    return (a > b) - (a < b)

print(cmp(list1, list2))
print(cmp(list2, list1))
1
-1

Re: ฟังก์ชัน Built in List ทำไมถึง error ที่ print(cmp(list1, list2))

โดย tatiya » 19/06/2019 6:47 pm

ใช้ python เวอร์ชั่นไหนครับ

ฟังก์ชัน Built in List ทำไมถึง error ที่ print(cmp(list1, list2))

โดย jirawoot » 19/06/2019 4:21 pm

โค้ด: เลือกทั้งหมด

list1 =["python", "helloworld", 2013,2024,3]
list2=[1,2,3,4,5,6]

print(cmp(list1, list2))
print(cmp(list2, list1))
Selection_022213.png
Selection_022213.png (15.28 KiB) Viewed 450 times

ข้างบน