รวมความมึนของผม ใน python

rules = (
    ( 'foo', 1),
    ( 'spam', 2),
    ( 'bar', 3),
"""
    ( 'egg', 4),
    ( 'python', 5),
"""
)

for name, val in rules:
    print name, val

โค้ดข้างบนพอรันแล้วจะเจอ ValueError (too many values to unpack)
ตอนมองแว๊บแรก ก็คิดว่าโค้ดน่าจะโอเค แค่ comment egg กับ python ออกไปแบบหลายบรรทัด… แต่จริงๆ แล้วมันไม่ใช่

เราสร้าง list ที่มี (‘foo’, 1), (‘spam’, 2), (‘bar’, 3) และ “”” (‘egg’, 4),…””” <– ก้อนนี้เป็น string แบบหลายบรรทัด ไม่ใช่ comment!!

ปล. ตอนนี้มีอยู่ 1 bug, เดี๋ยวมีอะไรเพิ่ม จะเอามาแปะอีกครับ

3 ความเห็นบน “รวมความมึนของผม ใน python

ใส่ความเห็น

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  เปลี่ยนแปลง )

Facebook photo

You are commenting using your Facebook account. Log Out /  เปลี่ยนแปลง )

Connecting to %s