Searching...
ไทย
EnglishEnglish
EspañolSpanish
简体中文Chinese
FrançaisFrench
DeutschGerman
日本語Japanese
PortuguêsPortuguese
ItalianoItalian
한국어Korean
РусскийRussian
NederlandsDutch
العربيةArabic
PolskiPolish
हिन्दीHindi
Tiếng ViệtVietnamese
SvenskaSwedish
ΕλληνικάGreek
TürkçeTurkish
ไทยThai
ČeštinaCzech
RomânăRomanian
MagyarHungarian
УкраїнськаUkrainian
Bahasa IndonesiaIndonesian
DanskDanish
SuomiFinnish
БългарскиBulgarian
עבריתHebrew
NorskNorwegian
HrvatskiCroatian
CatalàCatalan
SlovenčinaSlovak
LietuviųLithuanian
SlovenščinaSlovenian
СрпскиSerbian
EestiEstonian
LatviešuLatvian
فارسیPersian
മലയാളംMalayalam
தமிழ்Tamil
اردوUrdu
Learning Python

Learning Python

โดย Mark Lutz 2013 1214 หน้า
4.01
3.2K คะแนน
ฟัง
Try Full Access for 7 Days
Unlock listening & more!
Continue

ข้อสำคัญ

1. ประเภทข้อมูลหลักของ Python: ตัวเลข สตริง รายการ และพจนานุกรม

วัตถุที่มีมาให้ในตัวช่วยให้เขียนโปรแกรมได้ง่ายขึ้น

บล็อกพื้นฐานที่หลากหลายและแข็งแกร่ง ประเภทข้อมูลหลักของ Python เป็นรากฐานที่มั่นคงสำหรับการเขียนโปรแกรม ตัวเลขรองรับการคำนวณทางคณิตศาสตร์ สตริงจัดการกับข้อความ รายการเก็บรวบรวมข้อมูลแบบมีลำดับ และพจนานุกรมเก็บข้อมูลแบบคู่กุญแจ-ค่า ประเภทข้อมูลเหล่านี้อาจเปลี่ยนแปลงได้หรือไม่ได้ ซึ่งส่งผลต่อวิธีการแก้ไขข้อมูล

การดำเนินการที่ทรงพลัง แต่ละประเภทมาพร้อมกับชุดคำสั่งและเมธอดในตัว เช่น

  • สตริง: การตัดข้อความ การเชื่อมต่อ และเมธอดอย่าง split() กับ join()
  • รายการ: การเข้าถึงด้วยดัชนี การตัดข้อความ append() และ extend()
  • พจนานุกรม: การเข้าถึงด้วยกุญแจ การอัปเดตด้วย update() และเมธอด keys()

ความยืดหยุ่นและประสิทธิภาพ ประเภทข้อมูลหลักของ Python ถูกออกแบบมาเพื่อใช้งานง่ายและมีประสิทธิภาพ สามารถซ้อนกันเพื่อสร้างโครงสร้างข้อมูลที่ซับซ้อนได้ และหลายคำสั่งถูกปรับแต่งให้ทำงานได้รวดเร็ว การผสมผสานระหว่างความเรียบง่ายและพลังนี้ทำให้ Python เหมาะกับงานเขียนโปรแกรมหลากหลายรูปแบบ

2. การพิมพ์แบบไดนามิกและการอ้างอิงใน Python

ชื่อไม่มีชนิดข้อมูล แต่ตัววัตถุมี

ความยืดหยุ่นของชนิดข้อมูล Python ใช้การพิมพ์แบบไดนามิก หมายความว่าตัวแปรสามารถอ้างอิงถึงวัตถุได้ทุกชนิด ซึ่งช่วยให้โค้ดมีความยืดหยุ่นและกระชับ เพราะตัวแปรเดียวกันสามารถเก็บข้อมูลชนิดต่าง ๆ ได้ในเวลาต่างกัน แต่ก็ต้องระมัดระวังเรื่องความเข้ากันได้ของชนิดข้อมูลในระหว่างการดำเนินการ

โมเดลการอ้างอิง ใน Python ตัวแปรเป็นเพียงชื่อที่อ้างอิงถึงวัตถุในหน่วยความจำ เมื่อกำหนดค่าตัวแปร คุณกำลังสร้างการอ้างอิงไปยังวัตถุนั้น ซึ่งมีผลสำคัญดังนี้

  • ชื่อหลายชื่อสามารถอ้างอิงวัตถุเดียวกันได้
  • วัตถุที่เปลี่ยนแปลงได้สามารถถูกแก้ไขโดยตรง ส่งผลต่อทุกการอ้างอิง
  • วัตถุที่ไม่เปลี่ยนแปลงจะสร้างวัตถุใหม่เมื่อถูก "แก้ไข"

ความเข้าใจโมเดลการอ้างอิงนี้เป็นสิ่งจำเป็นสำหรับการเขียนโค้ด Python ที่มีประสิทธิภาพและปราศจากข้อผิดพลาด โดยเฉพาะเมื่อจัดการกับอาร์กิวเมนต์ของฟังก์ชันและโครงสร้างข้อมูลที่ใช้ร่วมกัน

3. ไวยากรณ์และโครงสร้างของคำสั่งใน Python

ขอบเขตของบล็อกและคำสั่งถูกตรวจจับโดยอัตโนมัติ

การเยื้องบรรทัดสำคัญ ต่างจากภาษาอื่น ๆ Python ใช้การเยื้องบรรทัดเพื่อกำหนดบล็อกของโค้ด ซึ่งช่วยบังคับให้โค้ดสะอาดและอ่านง่ายโดยธรรมชาติ เครื่องหมายโคลอน (:) ใช้เพื่อเริ่มบล็อกในคำสั่งที่ซับซ้อน เช่น if, for, while และการกำหนดฟังก์ชัน

ประเภทของคำสั่ง Python มีคำสั่งหลากหลายประเภท เช่น

  • คำสั่งกำหนดค่า (=, +=, ฯลฯ)
  • คำสั่งเงื่อนไข (if, elif, else)
  • คำสั่งลูป (for, while)
  • การกำหนดฟังก์ชันและคลาส (def, class)
  • การจัดการข้อผิดพลาด (try, except, finally)

ความเรียบง่ายและอ่านง่าย ไวยากรณ์ของ Python ถูกออกแบบให้ชัดเจนและเข้าใจง่าย หลายคำสั่งที่ต้องใช้หลายบรรทัดในภาษาอื่น สามารถเขียนได้อย่างกระชับใน Python เช่น list comprehensions และนิพจน์เงื่อนไข

4. การวนซ้ำและโครงสร้างลูปใน Python

ลูป for และ list comprehensions มักเป็นวิธีที่ง่ายและรวดเร็วที่สุดในการทำงานจริงใน Python

เครื่องมือการวนซ้ำที่ทรงพลัง Python มีวิธีการวนซ้ำข้อมูลหลายแบบ เช่น

  • ลูป for สำหรับลำดับและ iterable อื่น ๆ
  • ลูป while สำหรับการวนซ้ำตามเงื่อนไข
  • List comprehensions สำหรับการแปลงข้อมูลอย่างกระชับ
  • Generator expressions สำหรับการวนซ้ำที่ประหยัดหน่วยความจำ

โปรโตคอล iterable โมเดลการวนซ้ำของ Python อิงตามโปรโตคอล iterable ซึ่งอนุญาตให้วัตถุที่กำหนดเองสามารถวนซ้ำได้ วิธีนี้ทำให้ฟังก์ชันและโครงสร้างในตัวหลายอย่างทำงานร่วมกับชนิดข้อมูลที่ผู้ใช้สร้างขึ้นได้อย่างราบรื่น

ประสิทธิภาพและความอ่านง่าย การวนซ้ำใน Python ถูกออกแบบให้ทั้งมีประสิทธิภาพและอ่านง่าย ตัวอย่างเช่น list comprehensions สามารถแทนที่ลูป for หลายบรรทัดด้วยบรรทัดเดียวที่แสดงความหมายชัดเจน ฟังก์ชันในตัวอย่าง range(), enumerate(), และ zip() ยังช่วยเพิ่มพลังและความยืดหยุ่นของเครื่องมือวนซ้ำใน Python

5. ฟังก์ชัน: บล็อกโค้ดที่นำกลับมาใช้ซ้ำได้ใน Python

ฟังก์ชันเป็นโครงสร้างโปรแกรมพื้นฐานที่สุดที่ Python มีเพื่อเพิ่มการนำโค้ดกลับมาใช้ซ้ำและลดความซ้ำซ้อนของโค้ด

การจัดระเบียบโค้ดแบบโมดูลาร์ ฟังก์ชันใน Python ช่วยให้คุณรวบรวมโค้ดที่นำกลับมาใช้ซ้ำได้ ซึ่งส่งเสริม

  • การนำโค้ดกลับมาใช้ซ้ำและลดความซ้ำซ้อน
  • การบำรุงรักษาและแก้ไขข้อผิดพลาดที่ง่ายขึ้น
  • การอ่านและการจัดระเบียบที่ดีขึ้น

อาร์กิวเมนต์ที่ยืดหยุ่น ฟังก์ชันใน Python รองรับพารามิเตอร์หลายประเภท เช่น

  • อาร์กิวเมนต์ตำแหน่ง
  • อาร์กิวเมนต์แบบคีย์เวิร์ด
  • ค่าเริ่มต้นของอาร์กิวเมนต์
  • รายการอาร์กิวเมนต์ที่มีความยาวไม่จำกัด (*args, **kwargs)

ค่าที่ส่งกลับและผลข้างเคียง ฟังก์ชันสามารถส่งค่ากลับอย่างชัดเจนด้วยคำสั่ง return หรือส่งกลับ None โดยปริยาย นอกจากนี้ยังสามารถสร้างผลข้างเคียงโดยการแก้ไขวัตถุที่เปลี่ยนแปลงได้หรือเปลี่ยนแปลงตัวแปรระดับโลก ความเข้าใจความแตกต่างระหว่างค่าที่ส่งกลับและผลข้างเคียงเป็นสิ่งสำคัญสำหรับการเขียนโค้ดที่ชัดเจนและคาดเดาได้

6. ขอบเขตและเนมสเปซใน Python

เมื่อคุณใช้ชื่อในโปรแกรม Python จะสร้าง เปลี่ยนแปลง หรือค้นหาชื่อนั้นในสิ่งที่เรียกว่าเนมสเปซ—ที่ซึ่งชื่อเหล่านั้นอาศัยอยู่

กฎ LEGB Python ใช้กฎ LEGB ในการแก้ไขชื่อ

  • Local: ชื่อที่กำหนดภายในฟังก์ชันปัจจุบัน
  • Enclosing: ชื่อในขอบเขตของฟังก์ชันที่ครอบคลุม
  • Global: ชื่อที่กำหนดในระดับบนสุดของโมดูล
  • Built-in: ชื่อในโมดูล built-in

การกำหนดชื่อและคำสั่ง global โดยปกติ การกำหนดค่าชื่อภายในฟังก์ชันจะสร้างหรือเปลี่ยนแปลงตัวแปรท้องถิ่น คำสั่ง global ช่วยให้คุณทำงานกับตัวแปรระดับโลกภายในขอบเขตฟังก์ชันได้อย่างชัดเจน

ผลกระทบของเนมสเปซ ความเข้าใจขอบเขตและเนมสเปซเป็นสิ่งสำคัญสำหรับ

  • การหลีกเลี่ยงความขัดแย้งของชื่อ
  • การจัดการอายุและการมองเห็นของตัวแปร
  • การเขียนโค้ดที่บำรุงรักษาง่ายและมีโครงสร้างดี

การใช้ขอบเขตอย่างเหมาะสมช่วยให้สร้างฟังก์ชันที่เป็นอิสระและนำกลับมาใช้ซ้ำได้มากขึ้น

7. โมดูลและการจัดระเบียบโค้ดใน Python

โมดูลคือชุดของตัวแปร หรือก็คือเนมสเปซ

การจัดระเบียบโค้ด โมดูลใน Python เป็นวิธีหลักในการจัดระเบียบโปรแกรมขนาดใหญ่

  • ไฟล์ .py แต่ละไฟล์คือโมดูลหนึ่งตัว
  • โมดูลสามารถประกอบด้วยตัวแปร ฟังก์ชัน และคลาส
  • โมดูลสามารถนำเข้าโมดูลอื่นได้

การจัดการเนมสเปซ โมดูลสร้างเนมสเปซแยกต่างหาก ซึ่งช่วยหลีกเลี่ยงความขัดแย้งของชื่อในโปรเจกต์ขนาดใหญ่ วิธีการแบบโมดูลาร์นี้ส่งเสริม

  • การนำโค้ดกลับมาใช้ซ้ำ
  • การจัดระเบียบฟังก์ชันอย่างมีเหตุผล
  • การบำรุงรักษาและการทำงานร่วมกันที่ง่ายขึ้น

กลไกการนำเข้า Python มีวิธีการนำเข้าและใช้งานโมดูลที่ยืดหยุ่น เช่น

  • import module
  • from module import name
  • from module import *
  • import module as alias

ความเข้าใจกลไกการนำเข้าเหล่านี้และผลกระทบของมันเป็นสิ่งจำเป็นสำหรับการจัดโครงสร้างโปรแกรม Python อย่างมีประสิทธิภาพและการจัดการความสัมพันธ์ระหว่างส่วนต่าง ๆ ของโค้ดคุณ

อัปเดตล่าสุด:

FAQ

What's Learning Python about?

  • Comprehensive Guide: Learning Python by Mark Lutz is a detailed introduction to the Python programming language, covering both basic and advanced topics.
  • Core Concepts: It focuses on Python's core concepts, including syntax, data types, and object-oriented programming (OOP) principles.
  • Practical Approach: The book includes practical examples and exercises to help readers apply concepts in real-world scenarios, making it suitable for both beginners and experienced programmers.

Why should I read Learning Python?

  • Authoritative Resource: Written by Mark Lutz, a leading figure in the Python community, the book is well-respected and widely used in educational settings.
  • Structured Learning Path: It is organized in a logical progression, starting from basic concepts and gradually introducing more advanced topics, making it suitable for self-study.
  • Updated Content: The third edition includes updates on Python 3.x features, ensuring that readers learn the most current practices and tools available in the language.

What are the key takeaways of Learning Python?

  • Core Concepts Mastery: Readers will gain a solid understanding of Python's fundamental concepts, including data types, control structures, functions, and modules.
  • OOP Principles: The book provides in-depth coverage of object-oriented programming, teaching readers how to design and implement classes and objects.
  • Practical Skills Application: Through exercises and examples, readers will learn how to apply their skills in real-world programming tasks, preparing them for actual coding challenges.

What are the best quotes from Learning Python and what do they mean?

  • "Python is a language that emphasizes readability.": This highlights Python's design philosophy, prioritizing clear and understandable code for easier collaboration and maintenance.
  • "Functions are the most basic way of avoiding code redundancy.": This emphasizes the importance of functions in programming for code reuse and organization.
  • "Classes provide new local scopes.": This points out that classes create their own namespaces, helping avoid name clashes and maintain clarity in larger programs.

How does Learning Python approach Object-Oriented Programming?

  • In-Depth OOP Coverage: The book dedicates significant sections to explaining OOP concepts such as inheritance, encapsulation, and polymorphism.
  • Practical Class Design: Readers learn how to design and implement their own classes, including using special methods for operator overloading.
  • Real-World Examples: Numerous examples demonstrate OOP in action, bridging the gap between theory and practice.

What is dynamic typing in Python according to Learning Python?

  • No Type Declarations: Variables do not require explicit type declarations; types are determined automatically at runtime based on the objects they reference.
  • Flexibility in Coding: This allows for greater flexibility, as variables can reference objects of different types throughout the program's execution.
  • Supports Polymorphism: Dynamic typing supports polymorphism, meaning the same operation can be applied to different types of objects, enhancing code reusability.

How do Python lists differ from strings in Learning Python?

  • Mutability: Lists are mutable, meaning they can be changed in-place, while strings are immutable and cannot be altered after creation.
  • Data Structure: Lists can hold a collection of items of any type, including other lists, whereas strings are specifically sequences of characters.
  • Operations: Lists support a variety of operations, such as appending and removing items, while strings support operations like concatenation and slicing.

How does exception handling work in Learning Python?

  • try/except Structure: The book explains the try/except structure for catching and handling exceptions, allowing programs to recover from errors gracefully.
  • Raising Exceptions: Readers learn how to raise exceptions manually using the raise statement, useful for signaling errors in their own code.
  • Using finally for Cleanup: The book discusses using finally clauses to ensure cleanup actions are always performed, critical for resource management.

What is the significance of the import statement in Python according to Learning Python?

  • Module Access: The import statement allows access to functions, classes, and variables defined in other modules, promoting code reuse and organization.
  • Namespace Management: Importing a module creates a separate namespace, preventing name collisions between variables in different modules.
  • Dynamic Loading: Python modules can be imported dynamically, allowing for flexible program structures where components can be loaded as needed.

How does Learning Python explain the difference between mutable and immutable types?

  • Mutable Types: Mutable types, such as lists and dictionaries, can be changed in place, allowing modification without creating a new object.
  • Immutable Types: Immutable types, like strings and tuples, cannot be changed once created, with any modification resulting in a new object.
  • Impact on Performance: Understanding the difference affects memory management and performance, as mutable types can lead to unintended side effects if not handled carefully.

How do I define and call a function in Python according to Learning Python?

  • Defining Functions: Functions are defined using the def keyword, followed by the function name and parentheses containing any parameters.
  • Calling Functions: To call a function, use its name followed by parentheses, passing any required arguments.
  • Example: For instance, def add(a, b): return a + b defines a function, and calling add(2, 3) would return 5.

How does Learning Python help with debugging?

  • Error Messages and Stack Traces: Python provides detailed error messages and stack traces when exceptions occur, aiding in debugging efforts.
  • Using try/except for Debugging: Try/except blocks can catch exceptions during development, allowing testing and debugging without terminating the program.
  • Testing Frameworks: The book introduces testing frameworks like PyUnit and Doctest, which help automate testing and debugging processes.

รีวิว

4.01 จาก 5
เฉลี่ยจาก 3.2K คะแนนจาก Goodreads และ Amazon.

หนังสือเล่าเรียนภาษาไพธอนเล่มนี้ได้รับเสียงวิจารณ์ที่หลากหลาย บางคนชื่นชมในความครบถ้วนและความชัดเจนของเนื้อหา เหมาะสำหรับทั้งผู้เริ่มต้นและโปรแกรมเมอร์ที่มีประสบการณ์แล้ว ขณะที่บางส่วนกลับวิจารณ์ถึงความยาวของหนังสือ ความซ้ำซาก และจังหวะการนำเสนอที่ช้า ผู้อ่านหลายคนชื่นชอบคำอธิบายอย่างละเอียดและการเปรียบเทียบกับภาษาโปรแกรมอื่น ๆ แต่ก็มีบางคนรู้สึกว่าข้อความเยิ่นเย้อและการจัดเรียงเนื้อหาไม่เป็นระบบ หนังสือเล่มนี้ยังได้รับการกล่าวถึงในเรื่องการอธิบายความแตกต่างระหว่างไพธอนเวอร์ชัน 2.x และ 3.x แม้ว่าจะมีผู้มองว่าเป็นแหล่งข้อมูลสำคัญ แต่ก็มีบางกลุ่มแนะนำให้ใช้วิธีการเรียนรู้หรือหนังสือเล่มอื่นที่เน้นการปฏิบัติจริงมากกว่าในการศึกษาภาษาไพธอน

Your rating:
4.52
89 คะแนน

เกี่ยวกับผู้เขียน

มาร์ก ลัทซ์ เป็นบุคคลที่มีชื่อเสียงโดดเด่นในชุมชนผู้ใช้ภาษาไพธอน ด้วยผลงานบุกเบิกด้านการสอนและการเขียนหนังสือเกี่ยวกับไพธอนที่ได้รับความนิยมสูงสุด เขาเป็นผู้เขียนหนังสือไพธอนที่ขายดีหลายเล่ม เช่น "Programming Python," "Python Pocket Reference," และ "Learning Python" ซึ่งทั้งหมดอยู่ในฉบับที่ 4 ลัทซ์เริ่มใช้ภาษาไพธอนตั้งแต่ปี 1992 และเริ่มสอนตั้งแต่ปี 1997 เขาได้จัดอบรมเกี่ยวกับไพธอนมากกว่า 250 ครั้ง โดยมีนักเรียนเข้าร่วมประมาณ 4,000 คน หนังสือของเขามียอดขายรวมประมาณ 250,000 เล่ม และได้รับการแปลเป็นหลายภาษา ลัทซ์สำเร็จการศึกษาด้านวิทยาการคอมพิวเตอร์จากมหาวิทยาลัยวิสคอนซิน และมีประสบการณ์ทำงานในฐานะนักพัฒนาซอฟต์แวร์มืออาชีพอย่างยาวนาน

Listen
Now playing
Learning Python
0:00
-0:00
Now playing
Learning Python
0:00
-0:00
Voice
Speed
Dan
Andrew
Michelle
Lauren
1.0×
+
200 words per minute
Queue
Home
Library
Get App
Create a free account to unlock:
Requests: Request new book summaries
Bookmarks: Save your favorite books
History: Revisit books later
Recommendations: Personalized for you
Ratings: Rate books & see your ratings
100,000+ readers
Try Full Access for 7 Days
Listen, bookmark, and more
Compare Features Free Pro
📖 Read Summaries
All summaries are free to read in 40 languages
🎧 Listen to Summaries
Listen to unlimited summaries in 40 languages
❤️ Unlimited Bookmarks
Free users are limited to 4
📜 Unlimited History
Free users are limited to 4
📥 Unlimited Downloads
Free users are limited to 1
Risk-Free Timeline
Today: Get Instant Access
Listen to full summaries of 73,530 books. That's 12,000+ hours of audio!
Day 4: Trial Reminder
We'll send you a notification that your trial is ending soon.
Day 7: Your subscription begins
You'll be charged on Jun 14,
cancel anytime before.
Consume 2.8x More Books
2.8x more books Listening Reading
Our users love us
100,000+ readers
"...I can 10x the number of books I can read..."
"...exceptionally accurate, engaging, and beautifully presented..."
"...better than any amazon review when I'm making a book-buying decision..."
Save 62%
Yearly
$119.88 $44.99/year
$3.75/mo
Monthly
$9.99/mo
Start a 7-Day Free Trial
7 days free, then $44.99/year. Cancel anytime.
Scanner
Find a barcode to scan

Settings
General
Widget
Loading...