Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python
Python
  1. Cumulative Nested Tuple Column Product ใน Python

    Cumulative Nested Tuple Column Product เมื่อต้องการหา Column Product แบบสะสม (Cumulative) ของ Nested Tuple (Tuple ของ Tuples) ใช้ zip() และ Nested Generator Expression ตัวอย่างโค้ด tuple_1 = ((11, 23), (41, 25), (22, 19)) tuple_2 = ((60, 73), (31, 91), (14, 14)) print(The first tuple is : ) print(

  2. วิธีประกาศ Global Variable ใน Python

    Global Variable ใน Python คืออะไร? Global Variable คือ Variable ที่ประกาศนอก Function แต่ต้องการใช้ภายใน Function ตัวอย่างพื้นฐาน def func(): print(a) # ใช้ Global Variable a = 10 func() # Output: 10 Variable a ประกาศนอก Function → Global Scope ใช้ได้ใน Function Local vs Global Scope a = 10

  3. Python เป็น Scripting Language หรือ Programming Language?

    Python เป็น Scripting Language ใช่ Python เป็น Scripting Language Scripting Language vs Programming Language ความแตกต่างหลัก: Scripting Language ไม่ต้อง Compile ตรงไปตรงมา Interpret Compiled Languages (C++, Java, Go): Source Code → Compiler → Machine Code → Execute Scripting/Interpreted La

  4. ใช้เวลานานแค่ไหนในการเรียน Python?

    ใช้เวลาเรียน Python กี่วัน? ความเร็วในการเรียนขึ้นอยู่กับ ความสนใจ, ความตั้งใจ และ ความสม่ำเสมอ ของแต่ละคน ระดับต่างๆ และเวลาประมาณ ระดับหัวข้อเวลาประมาณ Basics (พื้นฐาน)Variables, Data Types, Loops, Conditions, Functions, Basic I/O1-2 สัปดาห์ Intermediate (ก

  5. โปรแกรม Python เรียง List of Tuples ตามตัวอักษร

    Sort List of Tuples Alphabetically ใน Python เมื่อต้องการเรียง List of Tuples ตามตัวอักษร (Alphabetical Order) ใช้เมธอด sort() ซึ่งทำ In-place Sorting (เปลี่ยน List ตัวเอง) ตัวอย่างโค้ด def sort_tuple_vals(my_tup): # เรียงตาม Element Index 0 (ตัวแรกของแต่ละ Tuple) my_tup.sort(key=lambda x:

  6. หาค่าสูงสุดใน Record List ที่เป็น Tuple Attribute ใน Python

    Maximum Value in Record List as Tuple Attribute เมื่อต้องการหาค่าสูงสุดใน List ที่อยู่ภายใน Tuple Attribute ของแต่ละ Record ใช้ List Comprehension และ max() ตัวอย่างโค้ด my_list = [(Will, [67, 45, 89]), (Jam, [34, 56, 13]), (Pow, [99, 123, 89]), (Nyk, [0, 56, 5])] print(The list of tuples is : ) pr

  7. หา Index ของ Record ที่มีค่าน้อยที่สุดใน Tuple List Python

    Index Minimum Value Record in Tuple List เมื่อต้องการหา Tuple ที่มีค่าน้อยที่สุดใน Column เฉพาะ (แล้วคืนค่า Column อื่น) ใช้ min() และ operator.itemgetter ตัวอย่างโค้ด from operator import itemgetter my_list = [(Will, 45), (Jam, 13), (Pow, 89), (Nyk, 56)] print(The list is: ) print(my_list) # หา

  8. วิธีอ่าน CSV File ใน Python

    อ่าน CSV File ใน Python CSV (Comma Separated Values) เป็น Plain Text File ที่คั่นค่าด้วย Comma แทน Tabular Data รูปแบบ CSV Sr.No,Name,City,Age 1,Rahul,Kolkata,21 2,Karan,Amritsar,23 3,Priya,Bangalore,20 อ่าน CSV ด้วย Module csv import csv with open(ttp.csv, r) as file: filecontent = csv.reade

  9. Binary Search ใน Python อธิบายพร้อมตัวอย่าง

    Binary Search คืออะไร? Binary Search เป็น Searching Algorithm สำหรับค้นหา Element ใน Sorted Array เท่านั้น ไม่สามารถใช้กับ Unsorted Array ได้ Time Complexity: O(log n) (ดีกว่า Linear Search O(n) มาก) Binary Search ทำงานอย่างไร? เปรียบเทียบ Target กับ Middle Element ของ Array ถ้าเท่ากัน → เ

  10. Bubble Sort ใน Python คืออะไร อธิบายพร้อมตัวอย่าง

    Bubble Sort คืออะไร? Bubble Sort เป็น Sorting Algorithm สำหรับเรียง List ให้เป็น Ascending (หรือ Descending) Order เป็น Algorithm ที่เข้าใจง่ายที่สุด แต่ไม่ค่อยมีประสิทธิภาพ Time Complexity O(n²) ใช้ได้กับ Input ขนาดเล็ก แต่ไม่เหมาะกับ List ใหญ่ ข้อดี: In-place Sorting (ไม่ใช้ Extra Space) Space Co

  11. การดึงเอลีเมนต์ตัวสุดท้ายจาก List of Tuples ใน Python

    Rear Element Extraction from List of Tuples เมื่อต้องการดึงเอลีเมนต์ตัวสุดท้าย (Rear/Last Element) จากทุก Tuple ใน List of Tuples สามารถใช้ List Comprehension และ Negative Indexing ได้ ตัวอย่างโค้ด my_list = [(Will, 67, 45), (Jam, 34, 56), (Pow, 99, 123), (Nyk, 0, 56)] print(The list of tuples is :

  12. Modulo ของ Tuple Elements ใน Python

    Modulo Operation บน Tuple แบบ Element-wise เมื่อต้องการหา Modulo (เศษจากการหาร) ของ Tuple สองตัวแบบ Element-wise ใช้ zip() และ Generator Expression พร้อม Operator % ตัวอย่างโค้ด my_tuple_1 = (67, 45, 34, 56) my_tuple_2 = (99, 123, 10, 56) print(The first tuple is : ) print(my_tuple_1) print(The se

  13. Pairwise Addition ใน Tuple ด้วย Python

    Pairwise Addition ใน Tuple เมื่อต้องการบวก Element ที่อยู่ติดกันใน Tuple (Pairwise Addition) สามารถใช้ zip(), tuple() และ Generator Expression ได้ ตัวอย่างโค้ด my_tuple = (67, 45, 34, 56, 99, 123, 0, 56) print(The tuple is : ) print(my_tuple) # zip กับ tuple เดียวกันแต่ข้ามตัวแรก my_result = tuple

  14. วิธีเรียงลำดับ Dictionary ใน Python

    การเรียงลำดับ Dictionary ใน Python Dictionary ประกอบด้วย Key-Value Pairs สามารถเรียงได้ 2 แบบ: Sort by Key: เรียงตาม Key เรียงน้อยไปมาก (Value ไม่สนใจ) Sort by Value: เรียงตาม Value เรียงน้อยไปมาก วิธีที่ 1: เรียงตาม Key Input/Output Input: {2:90, 1:100, 8:3, 5:67, 3:5} Output: {1:100, 2

  15. Queue ใน Python คืออะไร อธิบายพร้อมตัวอย่าง

    Queue ใน Python คืออะไร? Queue เป็น Linear Data Structure ทำงานแบบ First In First Out (FIFO) Element ที่เข้าไปก่อนจะถูก Process ก่อน (เหมือนคิวรอรถบัส) ตัวอย่างในชีวิตจริง คิวรอรถบัส: คนมาก่อนอยู่หน้า คนตามมาต่อท้าย รถมา คนหน้าขึ้นก่อน (First In First Out) การ Implement Queue ใน Python วิธีที่ 1:

  16. Stack ใน Python อธิบายพร้อมตัวอย่าง

    Stack ใน Python คืออะไร? Stack เป็น Linear Data Structure ทำงานแบบ Last In First Out (LIFO) Element ที่เข้าไปสุดท้ายจะถูก Process ก่อน (เหมือนกองจาน) ตัวอย่างในชีวิตจริง กองจาน: จานแรกอยู่ล่างสุด จานสุดท้ายอยู่บนสุด ต้องการจาน ต้องยกจานบนสุดออกก่อน (Last In First Out) การ Implement Stack ใน Python

  17. การหา Combinations ของ Sum ระหว่าง Tuple ใน List of Tuples Python

    Combinations of Sum with Tuples in Tuple List เมื่อต้องการหา Combinations ของผลบวก (Sum) ระหว่าง Tuple ใน List of Tuples สามารถใช้ itertools.combinations และ List Comprehension ได้ itertools.combinations combinations(iterable, r) คืน Subsequence ความยาว r จาก Iterable แบบ Lexicographic Sort Order

  18. ทดสอบว่า Tuple มีค่า K อยู่หรือไม่ใน Python

    Test if Tuple Contains K Value เมื่อต้องการตรวจสอบว่า Tuple มีค่า K อยู่หรือไม่ สามารถใช้ any(), map() และ Lambda Function ได้ ฟังก์ชันที่ใช้ Lambda: Anonymous Function ด้วย lambda map(): ใช้ Function กับทุก Item ใน Iterable any(): คืน True ถ้ามี Element ใด Element หนึ่งเป็น True ตัว

  19. หาค่าสูงสุดของ Index เหมือนกันใน List of Tuples สองตัว Python

    Maximum of Similar Indices in Two Lists of Tuples เมื่อต้องการหาค่าสูงสุดของ Index ที่ตรงกันใน List of Tuples สอง List สามารถใช้ zip() และ List Comprehension ได้ ตัวอย่างโค้ด my_list_1 = [(67, 45), (34, 56), (99, 123)] my_list_2 = [(10, 56), (45, 0), (100, 12)] print(The first list is : ) print(my

  20. วิธีลบ Element ออกจาก List ใน Python

    ลบ Element ออกจาก List ใน Python List ใน Python เป็น Linear Data Structure เก็บ Element ใน Memory ติดกัน เข้าถึงด้วย Index มี Built-in Methods หลายอย่างสำหรับลบ Element 1. pop(index) - ลบตาม Index ลบ Element ที่ Index ที่ระบุ และคืนค่า Element ที่ลบ lst = [1, 2, 3, 4, 5] removed = lst.pop(2) # ลบ

Total 9001 -คอมพิวเตอร์  FirstPage PreviousPage NextPage LastPage CurrentPage:240/451  20-คอมพิวเตอร์/Page Goto:1 234 235 236 237 238 239 240 241 242 243 244 245 246