Devdit
 

วิธีแก้ไข Missing parentheses in call to 'print'. Did you mean print('Hello there!', end='')?

0.9K

ใช้ Python 3.X ลองรันโค้ดด้านล่าง แล้วขึ้น Error ว่า SyntaxError: Missing parentheses in call to 'print'. Did you mean print('Hello there!', end='')? แบบนี้ต้องแก้ไขอย่างไร ต้องการพิมพ์ข้อความโดยอยู่บรรทัดเดียวกัน แต่ใช้คำสั่ง print คนละคำสั่งกัน

print "Hello ",
print "My name is Python"

 

วิธีแก้ไข

กรณีใช้ Python 3.x แนะนำให้ใช้คำสั่ง end แทนเพื่อพิมพ์ข้อความบรรทัดเดียวกันโดยไม่ขึ้นบรรทัดใหม่ สามารถเขียนโปรแกรมได้ดังนี้

print("Hello", end = ' ')
print("My name is Python")

ผลลัพธ์

Hello My name is Python
แก้ไข 2 ปีที่แล้ว
ชอบ
ลิ้งก์
แชร์
Devdit มีช่อง YouTube แล้ว
เราสร้างวิดีโอเกี่ยวกับเทคโนโลยี ทำตามง่ายๆ