มือใหม่หัดใช้ python

  • warning: realpath() [function.realpath]: SAFE MODE Restriction in effect. The script whose uid is 1005 is not allowed to access /tmp owned by uid 0 in /var/www/sites/sugree/codenone.com/subdomains/www/html/includes/file.inc on line 190.
  • warning: realpath() [function.realpath]: SAFE MODE Restriction in effect. The script whose uid is 1005 is not allowed to access /tmp owned by uid 0 in /var/www/sites/sugree/codenone.com/subdomains/www/html/includes/file.inc on line 190.

ไม่ทราบว่า คำสั่ง print ใน python นั้นสามารถทำ แบบ code ภาษาซีแบบนี้ได้หรือไม่
printf("Hello %d %d",i,j);

ไม่ทราบว่าจะให้ python ทำแบบคำสั่งข้างบน จะต้องเขียนคำสั่งอย่างไรคัีบ

ไม่ต้องใช้ printf ครับ ใช้ print ธรรมดา เขียนกันซื่อ ๆ ตรง ๆ โดยมี , คั่นกลางได้เลยครับ เช่น

>>> i = 2
>>> j = 3
>>> print 'hallo',i,j
hallo 2 3
veer's picture

print "Hello %d %d" % (i,j)

ขอบคุณมากคับ จิงๆแล้วอยากจะทำแบบนี้

print "a[%d,%d] = " % (i,j)
ถูกใช่ไหมคับ

sugree's picture

ถูกแล้วครับ

you may like this trick

print "a[%(i)d, %(j)d]" % locals()

ย้าย Codenone

ประกาศย้าย Codenone ไปใช้ Forum ของ Blognone แทนครับ ตามไปตั้งกระทู้ต่อได้ที่ Codenone Forum (รายละเอียดอ่านจากกระทู้ ย้าย Codenone ไปรวมกับ Blognone)

กระทู้เก่าๆ จะย้ายตามไปในภายหลัง ตอนนี้ปิดการโพสต์กระทู้ไว้ เหลือไว้เฉพาะอ้างอิงเท่านั้น