Python’s assignment and parameter passing use object references; e.g., if
a
is a list and we assignb = a
, then any operation ona
will modifyb
, and vice versa.The
is
operation tests whether two objects are identical internal objects, whereas==
tests whether two objects are equivalent. This distinction parallels the type-token distinction.Strings, lists, and tuples are different kinds of sequence object, supporting common operations such as indexing, slicing,
len()
,sorted()
, and membership testing usingin
.We can write text to a file by opening the file for writing
ofile = open('output.txt', 'w'
then adding content to the file
ofile.write("Monty Python")
, and finally closing the fileofile.close()
.A declarative programming style usually produces more compact, readable code; manually incremented loop variables are usually unnecessary. When a sequence must be enumerated, use
enumerate()
.Functions are an essential programming abstraction: key concepts to understand are parameter passing, variable scope, and docstrings.
A function serves as a namespace: names defined inside a function are not visible outside that function, unless those names are declared to be global.
Modules permit logically related material to be localized in a file. A module serves as a namespace: names defined in a module—such as variables and functions—are not visible to other modules, unless those names are imported.
Dynamic programming is an algorithm design technique used widely in NLP that stores the results of previous computations in order to avoid unnecessary recomputation.
Get Natural Language Processing with Python now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.