Skip to content

Commit c731e05

Browse files
committed
Add escape characters, cleanup
1 parent 86387bc commit c731e05

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

python.rst

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,28 @@ Python 3 strings hold unicode data. Python has a few ways to represent strings.
261261
Byte string ``b'hello'``
262262
================ ===========================
263263

264+
.. table:: Escape Characters
265+
266+
=================== =================
267+
Escape Sequence Output
268+
=================== =================
269+
``\`` newline Ignore trailing newline in triple quoted string
270+
``\\`` Backslash
271+
``\'`` Single quote
272+
``\"`` Double quote
273+
``\a`` ASCII Bell
274+
``\b`` ASCII Backspace
275+
``\n`` Newline
276+
``\r`` ASCII carriage return
277+
``\t`` Tab
278+
``\u12af`` Unicode 16 bit
279+
``\U12af89bc`` Unicode 32 bit
280+
``N{BLACK STAR}`` Unicode name
281+
``\o84`` Octal character
282+
``\xFF`` Hex character
283+
=================== =================
284+
285+
264286

265287
.. longtable: format: {p{.3\textwidth} l >{\raggedright\arraybackslash}p{.3\textwidth}}
266288
@@ -579,17 +601,17 @@ We can access members by position or name (name allows us to be more explicit)::
579601
``"{}".format(t)`` ``__format__`` String format of tuple
580602
``t >= t2`` ``__ge__`` Greater or equal. Compares items in tuple from left
581603
``t[idx]`` ``__getitem__`` Index operation
582-
``t > l2`` ``__gt__`` Greater. Compares items in tuple from left
604+
``t > t2`` ``__gt__`` Greater. Compares items in tuple from left
583605
``hash(t)`` ``__hash__`` For set/dict insertion
584606
``for thing in t:`` ``__iter__`` Iteration
585607
``t <= t2`` ``__le__`` Less than or equal. Compares items in tuple from left
586-
``len(l)`` ``__len__`` Length
608+
``len(t)`` ``__len__`` Length
587609
``t < t2`` ``__lt__`` Less than. Compares items in tuple from left
588610
``t * 2`` ``__mul__`` Repetition
589-
``t != l2`` ``__ne__`` Not equal
611+
``t != t2`` ``__ne__`` Not equal
590612
``repr(t)`` ``__repr__`` Programmer friendly string
591613
``foo * t`` ``__rmul__`` Called if ``foo`` doesn't implement ``__mul__``
592-
``l.__sizeof__()`` ``__sizeof__`` Bytes for internal representation
614+
``t.__sizeof__()`` ``__sizeof__`` Bytes for internal representation
593615
``str(l)`` ``__str__`` User friendly string
594616
================================== ========================= ============================================================
595617

@@ -1183,7 +1205,7 @@ Functions can support variable keyword arguments::
11831205
but 1 was given
11841206

11851207

1186-
You can indicate the end of positional parameters by using a single ``*``. This gives you keyword only parameters (PEP 3102)::
1208+
You can indicate the end of positional parameters by using a single ``*``. This gives you *keyword only* parameters (PEP 3102)::
11871209

11881210
>>> def add_points(*, x1=0, y1=0, x2=0, y2=0):
11891211
... return x1 + x2, y1 + y2
@@ -1243,6 +1265,9 @@ You can also combine ``*`` and ``**`` on invocation::
12431265
>>> add_all(*sizes, **named_sizes)
12441266
10.5
12451267

1268+
Getting Help
1269+
------------
1270+
12461271
You can get help on a function that has a docstring by using ``help``::
12471272

12481273
>>> help(add_all)

0 commit comments

Comments
 (0)