更新时间:2021-07-02 22:17:48
coverpage
Title Page
Credits
About the Authors
www.PacktPub.com
Customer Feedback
Preface
Python Promo
Overview
What is Python?
It's a programming language!
Versions of the Python language
It's a standard library!
It's a philosophy
The journey of a thousand miles…
Errata and Suggestions
Conventions Used in This Book
Downloading the example code
Downloading the color images of this book
Getting started
Obtaining and installing Python 3
Windows
macOS
Linux
Starting Python command line REPL
Leaving the REPL
Unix
Code structure and significant indentation
Python culture
Importing standard library modules
Getting help()
Counting fruit with math.factorial()
Different types of numbers
Scalar data types: integers floats None and bool
int
float
Special floating point values
Promotion to float
None
bool
Relational operators
Rich comparison operators
Control flow: if-statements and while-loops
Conditional control flow: The if-statement
if...else
if...elif...else
Conditional repetition: the while-loop
Exiting loops with break
Summary
Strings and Collections
str – an immutable sequence of Unicode code points
String quoting styles
Moment of zen
Concatenation of adjacent strings
Multiline strings and newlines
Raw strings
The str constructor
Strings as sequences
String methods
Strings with Unicode
The bytes type – an immutable sequence of bytes
Literal bytes
Converting between bytes and str
list – a sequence of objects
The dict type – associating keys with values
The For-loops – iterating over series of items
Putting it all together
Modularity
Organizing code in a .py file
Running Python programs from the operating system shell
Importing modules into the REPL
Defining functions
Organizing our module into functions
The __name__ type and executing modules from the command line
The Python execution model
The difference between modules scripts and programs
Setting up a main function with command line argument
Accepting command line arguments
Docstrings
Comments
Shebang
Executable Python programs on Linux and Mac
Executable Python programs on Windows
Built-in types and the object model
The nature of Python object references
Reassigning a reference
Assigning one reference to another
Exploring value vs. identity with id()
Testing for equality of identity with is
Mutating without mutating
References to mutable objects
Equality of value (equivalence) versus equality of identity
Argument passing semantics – pass by object-reference
Modifying external objects in a function
Binding new objects in a function
Argument passing is reference binding