Newer
Older
13001
13002
13003
13004
13005
13006
13007
13008
13009
13010
13011
13012
13013
13014
13015
13016
13017
13018
13019
13020
13021
13022
13023
13024
13025
13026
13027
13028
13029
13030
13031
13032
13033
13034
13035
13036
13037
13038
13039
13040
13041
13042
13043
13044
13045
13046
13047
13048
13049
13050
13051
13052
13053
13054
13055
13056
13057
13058
13059
13060
13061
13062
13063
13064
13065
13066
13067
13068
13069
13070
13071
13072
13073
13074
13075
13076
13077
13078
13079
13080
13081
13082
13083
13084
13085
13086
'+----------------------------+----------------------------------+------------+\n'
'| "s[i:j:k]" | slice of *s* from *i* to *j* '
'| (3)(5) |\n'
'| | with step *k* '
'| |\n'
'+----------------------------+----------------------------------+------------+\n'
'| "len(s)" | length of *s* '
'| |\n'
'+----------------------------+----------------------------------+------------+\n'
'| "min(s)" | smallest item of *s* '
'| |\n'
'+----------------------------+----------------------------------+------------+\n'
'| "max(s)" | largest item of *s* '
'| |\n'
'+----------------------------+----------------------------------+------------+\n'
'| "s.index(x[, i[, j]])" | index of the first occurrence of '
'| (8) |\n'
'| | *x* in *s* (at or after index '
'| |\n'
'| | *i* and before index *j*) '
'| |\n'
'+----------------------------+----------------------------------+------------+\n'
'| "s.count(x)" | total number of occurrences of '
'| |\n'
'| | *x* in *s* '
'| |\n'
'+----------------------------+----------------------------------+------------+\n'
'\n'
'Sequences of the same type also support comparisons. In '
'particular,\n'
'tuples and lists are compared lexicographically by comparing\n'
'corresponding elements. This means that to compare equal, every\n'
'element must compare equal and the two sequences must be of the '
'same\n'
'type and have the same length. (For full details see '
'Comparisons in\n'
'the language reference.)\n'
'\n'
'Notes:\n'
'\n'
'1. While the "in" and "not in" operations are used only for '
'simple\n'
' containment testing in the general case, some specialised '
'sequences\n'
' (such as "str", "bytes" and "bytearray") also use them for\n'
' subsequence testing:\n'
'\n'
' >>> "gg" in "eggs"\n'
' True\n'
'\n'
'2. Values of *n* less than "0" are treated as "0" (which yields '
'an\n'
' empty sequence of the same type as *s*). Note that items in '
'the\n'
' sequence *s* are not copied; they are referenced multiple '
'times.\n'
' This often haunts new Python programmers; consider:\n'
'\n'
' >>> lists = [[]] * 3\n'
' >>> lists\n'
' [[], [], []]\n'
' >>> lists[0].append(3)\n'
' >>> lists\n'
' [[3], [3], [3]]\n'
'\n'
' What has happened is that "[[]]" is a one-element list '
'containing\n'
' an empty list, so all three elements of "[[]] * 3" are '
'references\n'
' to this single empty list. Modifying any of the elements of\n'
' "lists" modifies this single list. You can create a list of\n'
' different lists this way:\n'
'\n'
' >>> lists = [[] for i in range(3)]\n'
' >>> lists[0].append(3)\n'
' >>> lists[1].append(5)\n'
' >>> lists[2].append(7)\n'
' >>> lists\n'
' [[3], [5], [7]]\n'
'\n'
' Further explanation is available in the FAQ entry How do I '
'create a\n'
' multidimensional list?.\n'
'\n'
'3. If *i* or *j* is negative, the index is relative to the end '
'of\n'
' sequence *s*: "len(s) + i" or "len(s) + j" is substituted. '
'But\n'
' note that "-0" is still "0".\n'
13090
13091
13092
13093
13094
13095
13096
13097
13098
13099
13100
13101
13102
13103
13104
13105
13106
13107
'\n'
'4. The slice of *s* from *i* to *j* is defined as the sequence '
'of\n'
' items with index *k* such that "i <= k < j". If *i* or *j* '
'is\n'
' greater than "len(s)", use "len(s)". If *i* is omitted or '
'"None",\n'
' use "0". If *j* is omitted or "None", use "len(s)". If *i* '
'is\n'
' greater than or equal to *j*, the slice is empty.\n'
'\n'
'5. The slice of *s* from *i* to *j* with step *k* is defined as '
'the\n'
' sequence of items with index "x = i + n*k" such that "0 <= n '
'<\n'
' (j-i)/k". In other words, the indices are "i", "i+k", '
'"i+2*k",\n'
' "i+3*k" and so on, stopping when *j* is reached (but never\n'
' including *j*). When *k* is positive, *i* and *j* are '
'reduced to\n'
' "len(s)" if they are greater. When *k* is negative, *i* and '
'*j* are\n'
' reduced to "len(s) - 1" if they are greater. If *i* or *j* '
'are\n'
' omitted or "None", they become “end” values (which end '
'depends on\n'
' the sign of *k*). Note, *k* cannot be zero. If *k* is '
'"None", it\n'
' is treated like "1".\n'
'6. Concatenating immutable sequences always results in a new '
'object.\n'
' This means that building up a sequence by repeated '
'concatenation\n'
' will have a quadratic runtime cost in the total sequence '
'length.\n'
' To get a linear runtime cost, you must switch to one of the\n'
' alternatives below:\n'
13128
13129
13130
13131
13132
13133
13134
13135
13136
13137
13138
13139
13140
13141
13142
13143
13144
'\n'
' * if concatenating "str" objects, you can build a list and '
'use\n'
' "str.join()" at the end or else write to an "io.StringIO"\n'
' instance and retrieve its value when complete\n'
'\n'
' * if concatenating "bytes" objects, you can similarly use\n'
' "bytes.join()" or "io.BytesIO", or you can do in-place\n'
' concatenation with a "bytearray" object. "bytearray" '
'objects are\n'
' mutable and have an efficient overallocation mechanism\n'
'\n'
' * if concatenating "tuple" objects, extend a "list" instead\n'
'\n'
' * for other types, investigate the relevant class '
'documentation\n'
'\n'
'7. Some sequence types (such as "range") only support item '
'sequences\n'
' that follow specific patterns, and hence don’t support '
' concatenation or repetition.\n'
'\n'
'8. "index" raises "ValueError" when *x* is not found in *s*. Not '
'all\n'
' implementations support passing the additional arguments *i* '
'and\n'
' *j*. These arguments allow efficient searching of subsections '
'of\n'
' the sequence. Passing the extra arguments is roughly '
'equivalent to\n'
' using "s[i:j].index(x)", only without copying any data and '
'with the\n'
' returned index being relative to the start of the sequence '
'rather\n'
' than the start of the slice.\n'
13164
13165
13166
13167
13168
13169
13170
13171
13172
13173
13174
13175
13176
13177
13178
13179
13180
13181
13182
13183
13184
13185
13186
13187
13188
13189
13190
13191
13192
13193
13194
13195
13196
13197
13198
13199
13200
13201
13202
13203
13204
13205
13206
13207
'\n'
'\n'
'Immutable Sequence Types\n'
'========================\n'
'\n'
'The only operation that immutable sequence types generally '
'implement\n'
'that is not also implemented by mutable sequence types is '
'support for\n'
'the "hash()" built-in.\n'
'\n'
'This support allows immutable sequences, such as "tuple" '
'instances, to\n'
'be used as "dict" keys and stored in "set" and "frozenset" '
'instances.\n'
'\n'
'Attempting to hash an immutable sequence that contains '
'unhashable\n'
'values will result in "TypeError".\n'
'\n'
'\n'
'Mutable Sequence Types\n'
'======================\n'
'\n'
'The operations in the following table are defined on mutable '
'sequence\n'
'types. The "collections.abc.MutableSequence" ABC is provided to '
'make\n'
'it easier to correctly implement these operations on custom '
'sequence\n'
'types.\n'
'\n'
'In the table *s* is an instance of a mutable sequence type, *t* '
'is any\n'
'iterable object and *x* is an arbitrary object that meets any '
'type and\n'
'value restrictions imposed by *s* (for example, "bytearray" '
'only\n'
'accepts integers that meet the value restriction "0 <= x <= '
'255").\n'
'\n'
'+--------------------------------+----------------------------------+-----------------------+\n'
'| Operation | '
'Result | Notes |\n'
'|================================|==================================|=======================|\n'
13209
13210
13211
13212
13213
13214
13215
13216
13217
13218
13219
13220
13221
13222
13223
13224
13225
13226
13227
13228
13229
13230
13231
13232
13233
13234
13235
13236
13237
13238
13239
13240
'| "s[i] = x" | item *i* of *s* is replaced '
'by | |\n'
'| | '
'*x* | |\n'
'+--------------------------------+----------------------------------+-----------------------+\n'
'| "s[i:j] = t" | slice of *s* from *i* to *j* '
'is | |\n'
'| | replaced by the contents of '
'the | |\n'
'| | iterable '
'*t* | |\n'
'+--------------------------------+----------------------------------+-----------------------+\n'
'| "del s[i:j]" | same as "s[i:j] = '
'[]" | |\n'
'+--------------------------------+----------------------------------+-----------------------+\n'
'| "s[i:j:k] = t" | the elements of "s[i:j:k]" '
'are | (1) |\n'
'| | replaced by those of '
'*t* | |\n'
'+--------------------------------+----------------------------------+-----------------------+\n'
'| "del s[i:j:k]" | removes the elements '
'of | |\n'
'| | "s[i:j:k]" from the '
'list | |\n'
'+--------------------------------+----------------------------------+-----------------------+\n'
'| "s.append(x)" | appends *x* to the end of '
'the | |\n'
'| | sequence (same '
'as | |\n'
'| | "s[len(s):len(s)] = '
'[x]") | |\n'
'+--------------------------------+----------------------------------+-----------------------+\n'
'| "s.clear()" | removes all items from *s* '
'(same | (5) |\n'
'| | as "del '
's[:]") | |\n'
'+--------------------------------+----------------------------------+-----------------------+\n'
'| "s.copy()" | creates a shallow copy of '
13248
13249
13250
13251
13252
13253
13254
13255
13256
13257
13258
13259
13260
13261
13262
13263
13264
13265
13266
13267
13268
13269
'| | (same as '
'"s[:]") | |\n'
'+--------------------------------+----------------------------------+-----------------------+\n'
'| "s.extend(t)" or "s += t" | extends *s* with the contents '
'of | |\n'
'| | *t* (for the most part the '
'same | |\n'
'| | as "s[len(s):len(s)] = '
't") | |\n'
'+--------------------------------+----------------------------------+-----------------------+\n'
'| "s *= n" | updates *s* with its '
'contents | (6) |\n'
'| | repeated *n* '
'times | |\n'
'+--------------------------------+----------------------------------+-----------------------+\n'
'| "s.insert(i, x)" | inserts *x* into *s* at '
'the | |\n'
'| | index given by *i* (same '
'as | |\n'
'| | "s[i:i] = '
'[x]") | |\n'
'+--------------------------------+----------------------------------+-----------------------+\n'
'and | (2) |\n'
'| | also removes it from '
'*s* | |\n'
'+--------------------------------+----------------------------------+-----------------------+\n'
'| "s.remove(x)" | remove the first item from '
'*s* | (3) |\n'
'| | where "s[i]" is equal to '
'*x* | |\n'
'+--------------------------------+----------------------------------+-----------------------+\n'
'| "s.reverse()" | reverses the items of *s* '
'in | (4) |\n'
'| | '
'place | |\n'
'+--------------------------------+----------------------------------+-----------------------+\n'
'\n'
'Notes:\n'
'\n'
'1. *t* must have the same length as the slice it is replacing.\n'
'\n'
'2. The optional argument *i* defaults to "-1", so that by '
'default the\n'
' last item is removed and returned.\n'
'3. "remove()" raises "ValueError" when *x* is not found in *s*.\n'
'4. The "reverse()" method modifies the sequence in place for '
'economy\n'
' of space when reversing a large sequence. To remind users '
'that it\n'
' operates by side effect, it does not return the reversed '
'sequence.\n'
'\n'
'5. "clear()" and "copy()" are included for consistency with the\n'
' interfaces of mutable containers that don’t support slicing\n'
' operations (such as "dict" and "set"). "copy()" is not part '
'of the\n'
' "collections.abc.MutableSequence" ABC, but most concrete '
'mutable\n'
' sequence classes provide it.\n'
13310
13311
13312
13313
13314
13315
13316
13317
13318
13319
13320
13321
13322
13323
13324
13325
13326
13327
13328
13329
13330
13331
13332
13333
13334
13335
13336
13337
'\n'
' New in version 3.3: "clear()" and "copy()" methods.\n'
'\n'
'6. The value *n* is an integer, or an object implementing\n'
' "__index__()". Zero and negative values of *n* clear the '
'sequence.\n'
' Items in the sequence are not copied; they are referenced '
'multiple\n'
' times, as explained for "s * n" under Common Sequence '
'Operations.\n'
'\n'
'\n'
'Lists\n'
'=====\n'
'\n'
'Lists are mutable sequences, typically used to store collections '
'of\n'
'homogeneous items (where the precise degree of similarity will '
'vary by\n'
'application).\n'
'\n'
'class list([iterable])\n'
'\n'
' Lists may be constructed in several ways:\n'
'\n'
' * Using a pair of square brackets to denote the empty list: '
'"[]"\n'
'\n'
' * Using square brackets, separating items with commas: "[a]", '
'"[a,\n'
' b, c]"\n'
'\n'
' * Using a list comprehension: "[x for x in iterable]"\n'
'\n'
' * Using the type constructor: "list()" or "list(iterable)"\n'
'\n'
' The constructor builds a list whose items are the same and in '
'the\n'
' same order as *iterable*’s items. *iterable* may be either '
13349
13350
13351
13352
13353
13354
13355
13356
13357
13358
13359
13360
13361
13362
13363
13364
13365
13366
13367
13368
'a\n'
' sequence, a container that supports iteration, or an '
'iterator\n'
' object. If *iterable* is already a list, a copy is made and\n'
' returned, similar to "iterable[:]". For example, '
'"list(\'abc\')"\n'
' returns "[\'a\', \'b\', \'c\']" and "list( (1, 2, 3) )" '
'returns "[1, 2,\n'
' 3]". If no argument is given, the constructor creates a new '
'empty\n'
' list, "[]".\n'
'\n'
' Many other operations also produce lists, including the '
'"sorted()"\n'
' built-in.\n'
'\n'
' Lists implement all of the common and mutable sequence '
'operations.\n'
' Lists also provide the following additional method:\n'
'\n'
' sort(*, key=None, reverse=False)\n'
13370
13371
13372
13373
13374
13375
13376
13377
13378
13379
13380
13381
13382
13383
13384
13385
13386
13387
13388
13389
13390
13391
13392
13393
13394
13395
13396
13397
13398
13399
13400
13401
13402
13403
13404
13405
13406
13407
13408
13409
13410
13411
13412
13413
13414
'\n'
' This method sorts the list in place, using only "<" '
'comparisons\n'
' between items. Exceptions are not suppressed - if any '
'comparison\n'
' operations fail, the entire sort operation will fail (and '
'the\n'
' list will likely be left in a partially modified state).\n'
'\n'
' "sort()" accepts two arguments that can only be passed by\n'
' keyword (keyword-only arguments):\n'
'\n'
' *key* specifies a function of one argument that is used '
'to\n'
' extract a comparison key from each list element (for '
'example,\n'
' "key=str.lower"). The key corresponding to each item in '
'the list\n'
' is calculated once and then used for the entire sorting '
'process.\n'
' The default value of "None" means that list items are '
'sorted\n'
' directly without calculating a separate key value.\n'
'\n'
' The "functools.cmp_to_key()" utility is available to '
'convert a\n'
' 2.x style *cmp* function to a *key* function.\n'
'\n'
' *reverse* is a boolean value. If set to "True", then the '
'list\n'
' elements are sorted as if each comparison were reversed.\n'
'\n'
' This method modifies the sequence in place for economy of '
'space\n'
' when sorting a large sequence. To remind users that it '
'operates\n'
' by side effect, it does not return the sorted sequence '
'(use\n'
' "sorted()" to explicitly request a new sorted list '
'instance).\n'
'\n'
' The "sort()" method is guaranteed to be stable. A sort '
'is\n'
' stable if it guarantees not to change the relative order '
'of\n'
' elements that compare equal — this is helpful for sorting '
'in\n'
' multiple passes (for example, sort by department, then by '
'salary\n'
' grade).\n'
'\n'
' For sorting examples and a brief sorting tutorial, see '
'Sorting\n'
' HOW TO.\n'
'\n'
13425
13426
13427
13428
13429
13430
13431
13432
13433
13434
13435
13436
13437
13438
13439
13440
13441
13442
13443
13444
13445
13446
13447
13448
13449
13450
13451
13452
13453
13454
13455
13456
13457
13458
13459
13460
13461
13462
13463
13464
13465
' **CPython implementation detail:** While a list is being '
'sorted,\n'
' the effect of attempting to mutate, or even inspect, the '
'list is\n'
' undefined. The C implementation of Python makes the list '
'appear\n'
' empty for the duration, and raises "ValueError" if it can '
'detect\n'
' that the list has been mutated during a sort.\n'
'\n'
'\n'
'Tuples\n'
'======\n'
'\n'
'Tuples are immutable sequences, typically used to store '
'collections of\n'
'heterogeneous data (such as the 2-tuples produced by the '
'"enumerate()"\n'
'built-in). Tuples are also used for cases where an immutable '
'sequence\n'
'of homogeneous data is needed (such as allowing storage in a '
'"set" or\n'
'"dict" instance).\n'
'\n'
'class tuple([iterable])\n'
'\n'
' Tuples may be constructed in a number of ways:\n'
'\n'
' * Using a pair of parentheses to denote the empty tuple: '
'"()"\n'
'\n'
' * Using a trailing comma for a singleton tuple: "a," or '
'"(a,)"\n'
'\n'
' * Separating items with commas: "a, b, c" or "(a, b, c)"\n'
'\n'
' * Using the "tuple()" built-in: "tuple()" or '
'"tuple(iterable)"\n'
'\n'
' The constructor builds a tuple whose items are the same and '
'in the\n'
' same order as *iterable*’s items. *iterable* may be either '
13467
13468
13469
13470
13471
13472
13473
13474
13475
13476
13477
13478
13479
13480
13481
13482
13483
13484
13485
13486
13487
13488
13489
13490
13491
13492
13493
13494
13495
13496
13497
13498
13499
13500
13501
13502
13503
13504
13505
13506
13507
13508
13509
13510
13511
13512
13513
13514
13515
13516
13517
13518
13519
13520
13521
13522
13523
13524
13525
13526
13527
13528
13529
13530
13531
13532
13533
13534
13535
13536
13537
13538
13539
13540
13541
13542
13543
13544
13545
13546
13547
13548
13549
13550
13551
13552
13553
13554
13555
13556
13557
13558
13559
13560
13561
13562
13563
13564
13565
13566
13567
13568
13569
13570
13571
13572
13573
13574
13575
13576
13577
13578
13579
13580
13581
13582
13583
13584
13585
13586
13587
13588
13589
13590
13591
13592
13593
13594
'a\n'
' sequence, a container that supports iteration, or an '
'iterator\n'
' object. If *iterable* is already a tuple, it is returned\n'
' unchanged. For example, "tuple(\'abc\')" returns "(\'a\', '
'\'b\', \'c\')"\n'
' and "tuple( [1, 2, 3] )" returns "(1, 2, 3)". If no argument '
'is\n'
' given, the constructor creates a new empty tuple, "()".\n'
'\n'
' Note that it is actually the comma which makes a tuple, not '
'the\n'
' parentheses. The parentheses are optional, except in the '
'empty\n'
' tuple case, or when they are needed to avoid syntactic '
'ambiguity.\n'
' For example, "f(a, b, c)" is a function call with three '
'arguments,\n'
' while "f((a, b, c))" is a function call with a 3-tuple as the '
'sole\n'
' argument.\n'
'\n'
' Tuples implement all of the common sequence operations.\n'
'\n'
'For heterogeneous collections of data where access by name is '
'clearer\n'
'than access by index, "collections.namedtuple()" may be a more\n'
'appropriate choice than a simple tuple object.\n'
'\n'
'\n'
'Ranges\n'
'======\n'
'\n'
'The "range" type represents an immutable sequence of numbers and '
'is\n'
'commonly used for looping a specific number of times in "for" '
'loops.\n'
'\n'
'class range(stop)\n'
'class range(start, stop[, step])\n'
'\n'
' The arguments to the range constructor must be integers '
'(either\n'
' built-in "int" or any object that implements the "__index__"\n'
' special method). If the *step* argument is omitted, it '
'defaults to\n'
' "1". If the *start* argument is omitted, it defaults to "0". '
'If\n'
' *step* is zero, "ValueError" is raised.\n'
'\n'
' For a positive *step*, the contents of a range "r" are '
'determined\n'
' by the formula "r[i] = start + step*i" where "i >= 0" and '
'"r[i] <\n'
' stop".\n'
'\n'
' For a negative *step*, the contents of the range are still\n'
' determined by the formula "r[i] = start + step*i", but the\n'
' constraints are "i >= 0" and "r[i] > stop".\n'
'\n'
' A range object will be empty if "r[0]" does not meet the '
'value\n'
' constraint. Ranges do support negative indices, but these '
'are\n'
' interpreted as indexing from the end of the sequence '
'determined by\n'
' the positive indices.\n'
'\n'
' Ranges containing absolute values larger than "sys.maxsize" '
'are\n'
' permitted but some features (such as "len()") may raise\n'
' "OverflowError".\n'
'\n'
' Range examples:\n'
'\n'
' >>> list(range(10))\n'
' [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n'
' >>> list(range(1, 11))\n'
' [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n'
' >>> list(range(0, 30, 5))\n'
' [0, 5, 10, 15, 20, 25]\n'
' >>> list(range(0, 10, 3))\n'
' [0, 3, 6, 9]\n'
' >>> list(range(0, -10, -1))\n'
' [0, -1, -2, -3, -4, -5, -6, -7, -8, -9]\n'
' >>> list(range(0))\n'
' []\n'
' >>> list(range(1, 0))\n'
' []\n'
'\n'
' Ranges implement all of the common sequence operations '
'except\n'
' concatenation and repetition (due to the fact that range '
'objects\n'
' can only represent sequences that follow a strict pattern '
'and\n'
' repetition and concatenation will usually violate that '
'pattern).\n'
'\n'
' start\n'
'\n'
' The value of the *start* parameter (or "0" if the '
'parameter was\n'
' not supplied)\n'
'\n'
' stop\n'
'\n'
' The value of the *stop* parameter\n'
'\n'
' step\n'
'\n'
' The value of the *step* parameter (or "1" if the parameter '
'was\n'
' not supplied)\n'
'\n'
'The advantage of the "range" type over a regular "list" or '
'"tuple" is\n'
'that a "range" object will always take the same (small) amount '
'of\n'
'memory, no matter the size of the range it represents (as it '
'only\n'
'stores the "start", "stop" and "step" values, calculating '
'individual\n'
'items and subranges as needed).\n'
'\n'
'Range objects implement the "collections.abc.Sequence" ABC, and\n'
'provide features such as containment tests, element index '
'lookup,\n'
'slicing and support for negative indices (see Sequence Types — '
13596
13597
13598
13599
13600
13601
13602
13603
13604
13605
13606
13607
13608
13609
13610
13611
13612
13613
13614
13615
13616
13617
13618
13619
13620
13621
13622
13623
13624
13625
13626
13627
13628
13629
13630
13631
13632
'list,\n'
'tuple, range):\n'
'\n'
'>>> r = range(0, 20, 2)\n'
'>>> r\n'
'range(0, 20, 2)\n'
'>>> 11 in r\n'
'False\n'
'>>> 10 in r\n'
'True\n'
'>>> r.index(10)\n'
'5\n'
'>>> r[5]\n'
'10\n'
'>>> r[:5]\n'
'range(0, 10, 2)\n'
'>>> r[-1]\n'
'18\n'
'\n'
'Testing range objects for equality with "==" and "!=" compares '
'them as\n'
'sequences. That is, two range objects are considered equal if '
'they\n'
'represent the same sequence of values. (Note that two range '
'objects\n'
'that compare equal might have different "start", "stop" and '
'"step"\n'
'attributes, for example "range(0) == range(2, 1, 3)" or '
'"range(0, 3,\n'
'2) == range(0, 4, 2)".)\n'
'\n'
'Changed in version 3.2: Implement the Sequence ABC. Support '
'slicing\n'
'and negative indices. Test "int" objects for membership in '
'constant\n'
'time instead of iterating through all items.\n'
'\n'
'Changed in version 3.3: Define ‘==’ and ‘!=’ to compare range '
'objects\n'
'based on the sequence of values they define (instead of '
'comparing\n'
'based on object identity).\n'
'\n'
'New in version 3.3: The "start", "stop" and "step" attributes.\n'
'\n'
'See also:\n'
'\n'
' * The linspace recipe shows how to implement a lazy version of '
'range\n'
' suitable for floating point applications.\n',
'typesseq-mutable': 'Mutable Sequence Types\n'
13647
13648
13649
13650
13651
13652
13653
13654
13655
13656
13657
13658
13659
13660
13661
13662
13663
13664
13665
13666
13667
13668
13669
'**********************\n'
'\n'
'The operations in the following table are defined on '
'mutable sequence\n'
'types. The "collections.abc.MutableSequence" ABC is '
'provided to make\n'
'it easier to correctly implement these operations on '
'custom sequence\n'
'types.\n'
'\n'
'In the table *s* is an instance of a mutable sequence '
'type, *t* is any\n'
'iterable object and *x* is an arbitrary object that '
'meets any type and\n'
'value restrictions imposed by *s* (for example, '
'"bytearray" only\n'
'accepts integers that meet the value restriction "0 <= x '
'<= 255").\n'
'\n'
'+--------------------------------+----------------------------------+-----------------------+\n'
'| Operation | '
'Result | Notes '
'|\n'
'|================================|==================================|=======================|\n'
13671
13672
13673
13674
13675
13676
13677
13678
13679
13680
13681
13682
13683
13684
13685
13686
13687
13688
13689
13690
13691
13692
13693
13694
13695
13696
13697
13698
13699
13700
13701
13702
13703
13704
'| "s[i] = x" | item *i* of *s* is '
'replaced by | |\n'
'| | '
'*x* | '
'|\n'
'+--------------------------------+----------------------------------+-----------------------+\n'
'| "s[i:j] = t" | slice of *s* from *i* '
'to *j* is | |\n'
'| | replaced by the '
'contents of the | |\n'
'| | iterable '
'*t* | |\n'
'+--------------------------------+----------------------------------+-----------------------+\n'
'| "del s[i:j]" | same as "s[i:j] = '
'[]" | |\n'
'+--------------------------------+----------------------------------+-----------------------+\n'
'| "s[i:j:k] = t" | the elements of '
'"s[i:j:k]" are | (1) |\n'
'| | replaced by those of '
'*t* | |\n'
'+--------------------------------+----------------------------------+-----------------------+\n'
'| "del s[i:j:k]" | removes the elements '
'of | |\n'
'| | "s[i:j:k]" from the '
'list | |\n'
'+--------------------------------+----------------------------------+-----------------------+\n'
'| "s.append(x)" | appends *x* to the '
'end of the | |\n'
'| | sequence (same '
'as | |\n'
'| | "s[len(s):len(s)] = '
'[x]") | |\n'
'+--------------------------------+----------------------------------+-----------------------+\n'
'| "s.clear()" | removes all items '
'| | as "del '
's[:]") | |\n'
'+--------------------------------+----------------------------------+-----------------------+\n'
'| "s.copy()" | creates a shallow '
13711
13712
13713
13714
13715
13716
13717
13718
13719
13720
13721
13722
13723
13724
13725
13726
13727
13728
13729
13730
13731
13732
'| | (same as '
'"s[:]") | |\n'
'+--------------------------------+----------------------------------+-----------------------+\n'
'| "s.extend(t)" or "s += t" | extends *s* with the '
'contents of | |\n'
'| | *t* (for the most '
'part the same | |\n'
'| | as "s[len(s):len(s)] '
'= t") | |\n'
'+--------------------------------+----------------------------------+-----------------------+\n'
'| "s *= n" | updates *s* with its '
'contents | (6) |\n'
'| | repeated *n* '
'times | |\n'
'+--------------------------------+----------------------------------+-----------------------+\n'
'| "s.insert(i, x)" | inserts *x* into *s* '
'at the | |\n'
'| | index given by *i* '
'(same as | |\n'
'| | "s[i:i] = '
'[x]") | |\n'
'+--------------------------------+----------------------------------+-----------------------+\n'
'*i* and | (2) |\n'
'| | also removes it from '
'*s* | |\n'
'+--------------------------------+----------------------------------+-----------------------+\n'
'| "s.remove(x)" | remove the first item '
'from *s* | (3) |\n'
'| | where "s[i]" is equal '
'to *x* | |\n'
'+--------------------------------+----------------------------------+-----------------------+\n'
'| "s.reverse()" | reverses the items of '
'*s* in | (4) |\n'
'| | '
'place | '
'|\n'
'+--------------------------------+----------------------------------+-----------------------+\n'
'\n'
'Notes:\n'
'\n'
'1. *t* must have the same length as the slice it is '
'replacing.\n'
'\n'
'2. The optional argument *i* defaults to "-1", so that '
'by default the\n'
' last item is removed and returned.\n'
'3. "remove()" raises "ValueError" when *x* is not found '
'in *s*.\n'
'\n'
'4. The "reverse()" method modifies the sequence in place '
'for economy\n'
' of space when reversing a large sequence. To remind '
'users that it\n'
' operates by side effect, it does not return the '
'reversed sequence.\n'
'\n'
'5. "clear()" and "copy()" are included for consistency '
'with the\n'
' interfaces of mutable containers that don’t support '
' operations (such as "dict" and "set"). "copy()" is '
'not part of the\n'
' "collections.abc.MutableSequence" ABC, but most '
'concrete mutable\n'
' sequence classes provide it.\n'
'\n'
' New in version 3.3: "clear()" and "copy()" methods.\n'
'\n'
'6. The value *n* is an integer, or an object '
'implementing\n'
' "__index__()". Zero and negative values of *n* clear '
'the sequence.\n'
' Items in the sequence are not copied; they are '
'referenced multiple\n'
' times, as explained for "s * n" under Common Sequence '
'Operations.\n',
'unary': 'Unary arithmetic and bitwise operations\n'
13790
13791
13792
13793
13794
13795
13796
13797
13798
13799
13800
13801
13802
13803
13804
13805
13806
13807
13808
13809
13810
'***************************************\n'
'\n'
'All unary arithmetic and bitwise operations have the same '
'priority:\n'
'\n'
' u_expr ::= power | "-" u_expr | "+" u_expr | "~" u_expr\n'
'\n'
'The unary "-" (minus) operator yields the negation of its numeric\n'
'argument.\n'
'\n'
'The unary "+" (plus) operator yields its numeric argument '
'unchanged.\n'
'\n'
'The unary "~" (invert) operator yields the bitwise inversion of '
'its\n'
'integer argument. The bitwise inversion of "x" is defined as\n'
'"-(x+1)". It only applies to integral numbers.\n'
'\n'
'In all three cases, if the argument does not have the proper type, '
'a\n'
'"TypeError" exception is raised.\n',
'while': 'The "while" statement\n'
'*********************\n'
'\n'
'The "while" statement is used for repeated execution as long as an\n'
'expression is true:\n'
'\n'
' while_stmt ::= "while" assignment_expression ":" suite\n'
' ["else" ":" suite]\n'
'\n'
'This repeatedly tests the expression and, if it is true, executes '
'the\n'
'first suite; if the expression is false (which may be the first '
'time\n'
'it is tested) the suite of the "else" clause, if present, is '
'executed\n'
'and the loop terminates.\n'
'\n'
'A "break" statement executed in the first suite terminates the '
'loop\n'
'without executing the "else" clause’s suite. A "continue" '
'statement\n'
'executed in the first suite skips the rest of the suite and goes '
'back\n'
'to testing the expression.\n',
'with': 'The "with" statement\n'
'********************\n'
'\n'
'The "with" statement is used to wrap the execution of a block with\n'
'methods defined by a context manager (see section With Statement\n'
'Context Managers). This allows common "try"…"except"…"finally" '
'usage\n'
'patterns to be encapsulated for convenient reuse.\n'
'\n'
' with_stmt ::= "with" with_item ("," with_item)* ":" suite\n'
' with_item ::= expression ["as" target]\n'
'\n'
'The execution of the "with" statement with one “item” proceeds as\n'
'1. The context expression (the expression given in the "with_item") '
'is\n'
' evaluated to obtain a context manager.\n'
'2. The context manager’s "__enter__()" is loaded for later use.\n'
'3. The context manager’s "__exit__()" is loaded for later use.\n'
'4. The context manager’s "__enter__()" method is invoked.\n'
'\n'
'5. If a target was included in the "with" statement, the return '
'value\n'
' from "__enter__()" is assigned to it.\n'
'\n'
' Note:\n'
' The "with" statement guarantees that if the "__enter__()" '
'method\n'
' returns without an error, then "__exit__()" will always be\n'
' called. Thus, if an error occurs during the assignment to the\n'
' target list, it will be treated the same as an error occurring\n'
' within the suite would be. See step 6 below.\n'
'\n'
'7. The context manager’s "__exit__()" method is invoked. If an\n'
13876
13877
13878
13879
13880
13881
13882
13883
13884
13885
13886
13887
13888
13889
13890
13891
13892
13893
13894
' exception caused the suite to be exited, its type, value, and\n'
' traceback are passed as arguments to "__exit__()". Otherwise, '
'three\n'
' "None" arguments are supplied.\n'
'\n'
' If the suite was exited due to an exception, and the return '
'value\n'
' from the "__exit__()" method was false, the exception is '
'reraised.\n'
' If the return value was true, the exception is suppressed, and\n'
' execution continues with the statement following the "with"\n'
' statement.\n'
'\n'
' If the suite was exited for any reason other than an exception, '
'the\n'
' return value from "__exit__()" is ignored, and execution '
'proceeds\n'
' at the normal location for the kind of exit that was taken.\n'
'\n'
13895
13896
13897
13898
13899
13900
13901
13902
13903
13904
13905
13906
13907
13908
13909
13910
13911
13912
13913
13914
13915
13916
13917
13918
'The following code:\n'
'\n'
' with EXPRESSION as TARGET:\n'
' SUITE\n'
'\n'
'is semantically equivalent to:\n'
'\n'
' manager = (EXPRESSION)\n'
' enter = type(manager).__enter__\n'
' exit = type(manager).__exit__\n'
' value = enter(manager)\n'
' hit_except = False\n'
'\n'
' try:\n'
' TARGET = value\n'
' SUITE\n'
' except:\n'
' hit_except = True\n'
' if not exit(manager, *sys.exc_info()):\n'
' raise\n'
' finally:\n'
' if not hit_except:\n'
' exit(manager, None, None, None)\n'
'\n'
'With more than one item, the context managers are processed as if\n'
'multiple "with" statements were nested:\n'
'\n'
' with A() as a, B() as b:\n'
'\n'
' with A() as a:\n'
' with B() as b:\n'
'\n'
'Changed in version 3.1: Support for multiple context expressions.\n'
'\n'
'See also:\n'
'\n'
' **PEP 343** - The “with” statement\n'
' The specification, background, and examples for the Python '
'"with"\n'
' statement.\n',
'yield': 'The "yield" statement\n'
13940
13941
13942
13943
13944
13945
13946
13947
13948
13949
13950
13951
13952
13953
13954
13955
13956
13957
13958
13959
13960
13961
13962
13963
13964
13965
13966
13967
13968
13969
'*********************\n'
'\n'
' yield_stmt ::= yield_expression\n'
'\n'
'A "yield" statement is semantically equivalent to a yield '
'expression.\n'
'The yield statement can be used to omit the parentheses that would\n'
'otherwise be required in the equivalent yield expression '
'statement.\n'
'For example, the yield statements\n'
'\n'
' yield <expr>\n'
' yield from <expr>\n'
'\n'
'are equivalent to the yield expression statements\n'
'\n'
' (yield <expr>)\n'
' (yield from <expr>)\n'
'\n'
'Yield expressions and statements are only used when defining a\n'
'*generator* function, and are only used in the body of the '
'generator\n'
'function. Using yield in a function definition is sufficient to '
'cause\n'
'that definition to create a generator function instead of a normal\n'
'function.\n'
'\n'
'For full details of "yield" semantics, refer to the Yield '
'expressions\n'
'section.\n'}