โดย 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
built-in function นี้มันสามารถใช้ได้แค่ใน python 2 ครับ คุณน่าจะใช้ python3.x ใช่มั้ยครับ
หรือจะทำ function ขึ้นมาเอง จะประมาณนี้
[code]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))[/code]
1
-1