Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python
Python
  1. วิธีหาขนาดของ String ใน Python

    1. ความยาว (จำนวนตัวอักษร): ใช้ len() len(Hello World!) 12 2. ขนาดในหน่วย Bytes: ใช้ sys.getsizeof() getsizeof(Hello World!) 33 getsizeof() รวม overhead ของ object ด้วย

  2. วิธี Fill String ด้วย Spaces ใน Python

    ใช้ ljust(width[, fillchar]) pad ด้านขวา ตัวอย่าง print(Mona Lisa.ljust(12)) print(Mona Lisa.ljust(12, $)) ผลลัพธ์ Mona Lisa Mona Lisa$$$ สำหรับ pad ด้านซ้าย ใช้ rjust() แทน

Total 9001 -คอมพิวเตอร์  FirstPage PreviousPage NextPage LastPage CurrentPage:10/451  20-คอมพิวเตอร์/Page Goto:1 4 5 6 7 8 9 10 11 12 13 14 15 16