Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python
Python
  1. GNU Readline Completion ใน Python (โมดูล rlcompleter)

    โมดูล rlcompleter ให้ Tab Completion สำหรับ Python Interactive Mode ใช้ร่วมกับ readline import rlcompleter Completer Class คืนค่า Completion ตัวที่ state (0-based) # คืน None เมื่อหมดแล้ว โค้ดตัวอย่าง: ทดสอบ Completion import rlcompleter import sys completer = rlcompleter.Completer() test_p

  2. Basic Date and Time Types ใน Python (โมดูล datetime)

    โมดูล datetime ให้ Classes สำหรับจัดการ Date/Time: date, time, datetime, timedelta, tzinfo, timezone import datetime Class Overview ClassAttributesคำอธิบาย dateyear, month, dayวันที่อย่างเดียว (Gregorian Calendar) timehour, minute, second, microsecond, tzinfoเวลาอย่างเดียว (ไม่ผูกวันที่)

  3. Container Datatypes ใน Python (โมดูล collections)

    โมดูล collections ให้ Container Datatypes ที่ทรงพลังกว่า Built-ins (dict, list, set, tuple) Container Types ภาพรวม Classคำอธิบายใช้เมื่อไหร่ namedtupleTuple ที่มีชื่อ FieldImmutable Record, Lightweight Object dequeDouble-Ended Queue O(1)Queue, Stack, Sliding Window, BFS CounterDict Subcl

  4. Abstract Base Classes สำหรับ Containers ใน Python (collections.abc)

    โมดูล collections.abc ให้ Abstract Base Classes (ABCs) สำหรับ Container Types ใช้สร้าง Custom Containers ที่มีพฤติกรรมมาตรฐาน import collections.abc ABCs หลักสำหรับ Containers ABCExtendsAbstract Methods ที่ต้อง Implement Container-__contains__ Iterable-__iter__ IteratorIterable__next__,

  5. Heap Queue Algorithm ใน Python (โมดูล heapq)

    โมดูล heapq ให้ Min-Heap Implementation (Priority Queue) บน List ทำให้ Pop Minimum ได้ O(log n) import heapq หลักการ Min-Heap Root = Minimum Element (Priority 1 = สูงสุด) Parent ≤ Children เสมอ เก็บใน List แบบ Complete Binary Tree ฟังก์ชันหลัก FunctionคำอธิบายComplexity heapify(x

  6. Array Bisection Algorithm ใน Python (โมดูล bisect)

    โมดูล bisect ใช้ Binary Search หาตำแหน่ง Insert ใน Sorted List รักษาลำดับเรียงได้ใน O(log n) + O(n) Insert import bisect ฟังก์ชันหลัก FunctionคำอธิบายDuplicate Handling bisect_left(a, x, lo=0, hi=len(a))หาตำแหน่งซ้ายสุดที่ Insert ได้Insert ก่อน Duplicates bisect_right(a, x, lo=0, hi=len(a

  7. Weak References ใน Python (โมดูล weakref)

    Weak Reference อ้างอิง Object แต่ ไม่เพิ่ม Reference Count Object ถูก Garbage Collect ได้ปกติ เหมาะสำหรับ Cache, Observer Pattern, Circular Reference Prevention import weakref คลาสและฟังก์ชันหลัก Class/Functionคำอธิบาย weakref.ref(obj[, callback])สร้าง Weak Reference เรียก ref() ได้ Object

  8. Shallow Copy vs Deep Copy ใน Python (โมดูล copy)

    ใน Python การ Assign (=) ไม่ Copy Object แต่อ้างอิง (Reference) เดียวกัน โมดูล copy ให้ 2 ระดับการ Copy import copy Shallow Copy: copy.copy(x) สร้าง Object ใหม่ แต่ อ้างอิง Element เดียวกัน (Level 1 เท่านั้น) Nested Objects ยัง Share Reference ส่งผลต่อ Original Deep Copy: copy.deepcopy(

  9. Python Data Pretty Printer (โมดูล pprint)

    โมดูล pprint (Pretty Printer) จัดรูปแบบข้อมูล Complex ให้อ่านง่าย: เว้นบรรทัด, Indent, Sort Keys ใช้สำหรับ Debug, Logging, REPL import pprint ฟังก์ชันหลัก pprint.pprint(object, stream=None, indent=1, width=80, depth=None, compact=False, sort_dicts=True) Print สวยไปที่ Stream (Default: stdout) p

  10. Alternate repr() Implementation ใน Python (โมดูล reprlib)

    โมดูล reprlib ให้ repr() แบบจำกัดขนาด (Size-limited) เหมาะสำหรับ Debug ข้อมูลใหญ่ ไม่ให้ Output กวาดหน้าจอ import reprlib ฟังก์ชันหลัก reprlib.repr(obj) - คืน String แบบ Truncated (เหมือน repr แต่มี Limit) reprlib.aRepr - Instance Default Repr Object Class reprlib.Repr - ปรับแต่ง Limits

  11. Enumeration ใน Python (โมดูล enum)

    โมดูล enum ให้ Enumeration Type ใน Python (Python 3.4+) Enum มี Name และ Value เข้าถึงได้ทั้ง 2 แบบ import enum การสร้าง Enum พื้นฐาน import enum class Rainbow(enum.Enum): VIOLET = 1 INDIGO = 2 BLUE = 3 GREEN = 4 YELLOW = 5 ORANGE = 6 RED = 7 # เข้าถึง print(Rainbow(

  12. Python Mathematical Functions (โมดูล math)

    โมดูล math ใช้ cmath) import math Constants Constantค่าคำอธิบาย math.pi3.141592653589793π math.e2.718281828459045Natural Base math.tau6.2831853071795862π (Python 3.6+) math.infinfPositive Infinity math.nannanNot a Number Number Theory & Representation Functionคำอธิบาย ceil(x

  13. Secure Hashes และ Message Digest ใน Python (โมดูล hashlib)

    โมดูล hashlib ให้ Interface มาตรฐานสำหรับ Secure Hash Algorithms: SHA-1, SHA-2 (224, 256, 384, 512), SHA-3, BLAKE2, และ Legacy MD5 import hashlib Algorithms ที่รองรับ AlgorithmConstructorDigest SizeBlock Sizeหมายเหตุ MD5hashlib.md5()16 bytes (128 bits)64❌ ไม่ปลอดภัย สำหรับ Crypto SHA-1hash

  14. Keyed Hash (HMAC) ใน Python สำหรับ Message Authentication

    HMAC (Hash-based Message Authentication Code) ใช้ยืนยัน Integrity และ Authenticity ของข้อความ ด้วย Secret Key และ Hash Function (MD5, SHA-1, SHA-256, etc.) import hmac, import hashlib หลักการทำงาน HMAC(K, m) = H((K ⊕ opad) || H((K ⊕ ipad) || m)) K = Secret Key m = Message H = Hash Function

  15. Generate Secure Random Numbers ใน Python (โมดูล secrets)

    โมดูล secrets สร้าง Random Numbers แบบ Cryptographically Secure สำหรับ Password, Token, API Key, Session ID ใช้ Entropy จาก OS (os.urandom) import secrets (Python 3.6+) Random Numbers Functionคำอธิบาย secrets.SystemRandomClass ใช้ OS Random Source (เหมือน random.SystemRandom) secrets.choi

  16. Web Browser Controller ใน Python (โมดูล webbrowser)

    โมดูล webbrowser ให้ High-level Interface เปิดเว็บ/เอกสารใน Browser เริ่มต้น รองรับ Cross-platform import webbrowser เมธอดหลัก webbrowser.open(url, new=0, autoraise=True) new=0 - เปิดใน Tab/Window เดียวกัน (Default) new=1 - เปิด Window ใหม่ new=2 - เปิด Tab ใหม่ autoraise - ยก Window ขึ

  17. POSIX System Calls ใน Python (โมดูล posix)

    โมดูล posix ให้ Low-level POSIX System Calls บน UNIX ควรใช้ผ่าน os Module (Superset ของ posix) แทนการ Import โดยตรง import posix (หรือ import os) posix.environ Dictionary ของ Environment Variables (Bytes Keys/Values บน UNIX) print(posix.environ[bHOME]) # b/home/user **หมายเหตุ:** แก้ posix.envir

  18. เข้าถึง Password Database ใน Python (โมดูล pwd)

    โมดูล pwd ให้เข้าถึง UNIX Password Database (/etc/passwd) คืนค่าเป็น Named Tuple-like Object import pwd โครงสร้าง Password Entry IndexAttributeคำอธิบาย 0pw_nameLogin Name / Username 1pw_passwdEncrypted Password (ปัจจุบันมักเป็น x หรือ * ใช้ Shadow แทน) 2pw_uidUser ID (Numeric) 3pw_gidP

  19. เข้าถึง Shadow Password Database ใน Python (โมดูล spwd)

    โมดูล spwd ให้เข้าถึง UNIX Shadow Password Database (/etc/shadow) ต้องมีสิทธิ์ Root import spwd โครงสร้าง Shadow Entry IndexAttributeคำอธิบาย 0sp_nampLogin Name 1sp_pwdpEncrypted Password 2sp_lstchgวันสุดท้ายที่เปลี่ยน Password (Days since 1970-01-01) 3sp_minMin Days ระหว่างการเปลี่ยน

  20. เข้าถึง Group Database ใน Python (โมดูล grp)

    โมดูล grp ให้เข้าถึง UNIX Group Database (/etc/group) คืนค่าเป็น Named Tuple-like Object import grp โครงสร้าง Group Entry IndexAttributeคำอธิบาย 0gr_nameGroup Name 1gr_passwdEncrypted Password (ปกติเป็น x หรือ ว่าง) 2gr_gidGroup ID (Numeric) 3gr_memList ของ User Names ใน Group เมธอ

Total 9001 -คอมพิวเตอร์  FirstPage PreviousPage NextPage LastPage CurrentPage:77/451  20-คอมพิวเตอร์/Page Goto:1 71 72 73 74 75 76 77 78 79 80 81 82 83