title
stringlengths
4
62
text
stringlengths
12
9.02k
python_version
stringclasses
1 value
length
int64
12
9.02k
url
stringlengths
59
91
Contents
--- node2.html ref.html ref.html node79.html --- ## Contents - Introduction (node2.html#SECTION00200000000000000000) - Notation (node3.html#SECTION00210000000000000000) Lexical analysis (node4.html#SECTION00300000000000000000) - Line structure (node5.html#SECTION00310000000000000000) - Comments (node6.html#SECTION00311...
1.2
4,932
https://docs.python.org/{python_version}/python-ref/node1.html
Indentation
--- node11.html node5.html node9.html node1.html node79.html --- ## Indentation Leading whitespace (spaces and tabs) at the beginning of a logical line is used to compute the indentation level of the line, which in turn is used to determine the grouping of statements. First, tabs are replaced (from left to right) by on...
1.2
2,367
https://docs.python.org/{python_version}/python-ref/node10.html
Other tokens
--- node12.html node4.html node10.html node1.html node79.html --- # Other tokens Besides NEWLINE, INDENT and DEDENT, the following categories of tokens exist: identifiers, keywords, literals, operators, and delimiters. Spaces and tabs are not tokens, but serve to delimit tokens. Where ambiguity exists, a token comprise...
1.2
422
https://docs.python.org/{python_version}/python-ref/node11.html
Identifiers
--- node13.html node4.html node11.html node1.html node79.html --- # Identifiers Identifiers (also referred to as names) are described by the following lexical definitions: ```text identifier: (letter|"_") (letter|digit|"_")* letter: lowercase | uppercase lowercase: "a"..."z" uppercase: "A"..."Z" digit: "0"..."9" ``` Id...
1.2
449
https://docs.python.org/{python_version}/python-ref/node12.html
Keywords
--- node14.html node12.html node12.html node1.html node79.html --- ## Keywords The following identifiers are used as reserved words, or keywords of the language, and cannot be used as ordinary identifiers. They must be spelled exactly as written here: ```text access del from lambda return and elif global not try break ...
1.2
425
https://docs.python.org/{python_version}/python-ref/node13.html
Literals
--- node15.html node4.html node13.html node1.html node79.html --- # Literals Literals are notations for constant values of some built-in types. --- - String literals (node15.html#SECTION00341000000000000000) Numeric literals (node16.html#SECTION00342000000000000000) --- guido@cwi.nl
1.2
283
https://docs.python.org/{python_version}/python-ref/node14.html
String literals
--- node16.html node14.html node14.html node1.html node79.html --- ## String literals String literals are described by the following lexical definitions: ```text stringliteral: shortstring | longstring shortstring: "'" shortstringitem* "'" | '"' shortstringitem* '"' longstring: "'''" longstringitem* "'''" | '"""' longs...
1.2
1,622
https://docs.python.org/{python_version}/python-ref/node15.html
Numeric literals
--- node17.html node14.html node15.html node1.html node79.html --- ## Numeric literals There are three types of numeric literals: plain integers, long integers, and floating point numbers. Integer and long integer literals are described by the following lexical definitions: ```text longinteger: integer ("l"|"L") intege...
1.2
1,879
https://docs.python.org/{python_version}/python-ref/node16.html
Operators
--- node18.html node4.html node16.html node1.html node79.html --- # Operators The following tokens are operators: ```text + - * / % << >> & | ^ ~ < == > <= <> != >= ``` The comparison operators `<>` and `!=` are alternate spellings of the same operator. --- guido@cwi.nl
1.2
270
https://docs.python.org/{python_version}/python-ref/node17.html
Delimiters
--- node19.html node4.html node17.html node1.html node79.html --- # Delimiters The following tokens serve as delimiters or otherwise have a special meaning: ```text ( ) [ ] { } , : . " ` ' = ; ``` The following printing ASCII characters are not used in Python. Their occurrence outside string literals and comments is an...
1.2
436
https://docs.python.org/{python_version}/python-ref/node18.html
Data model
--- node20.html ref.html node18.html node1.html node79.html --- # Data model --- - Objects, values and types (node20.html#SECTION00410000000000000000) The standard type hierarchy (node21.html#SECTION00420000000000000000) Special method names (node22.html#SECTION00430000000000000000) - Special methods for any type (node...
1.2
694
https://docs.python.org/{python_version}/python-ref/node19.html
Introduction
--- node3.html ref.html node1.html node1.html node79.html --- # Introduction This reference manual describes the Python programming language. It is not intended as a tutorial. While I am trying to be as precise as possible, I chose to use English rather than formal specifications for everything except syntax and lexica...
1.2
1,650
https://docs.python.org/{python_version}/python-ref/node2.html
Objects, values and types
--- node21.html node19.html node19.html node1.html node79.html --- # Objects, values and types Objects are Python's abstraction for data. All data in a Python program is represented by objects or by relations between objects. (In a sense, and in conformance to Von Neumann's model of a ``stored program computer'', code ...
1.2
3,219
https://docs.python.org/{python_version}/python-ref/node20.html
The standard type hierarchy
--- node22.html node19.html node20.html node1.html node79.html --- # The standard type hierarchy Below is a list of the types that are built into Python. Extension modules written in C can define additional types. Future versions of Python may add types to the type hierarchy (e.g. rational or complex numbers, efficient...
1.2
930
https://docs.python.org/{python_version}/python-ref/node21.html
Special method names
--- node23.html node19.html node21.html node1.html node79.html --- # Special method names A class can implement certain operations that are invoked by special syntax (such as subscription or arithmetic operations) by defining methods with special names. For instance, if a class defines a method named `__getitem__`, and...
1.2
1,277
https://docs.python.org/{python_version}/python-ref/node22.html
Special methods for any type
--- node24.html node22.html node22.html node1.html node79.html --- ## Special methods for any type --- node24.html node22.html node22.html node1.html node79.html --- --- guido@cwi.nl
1.2
182
https://docs.python.org/{python_version}/python-ref/node23.html
Special methods for attribute access
--- node25.html node22.html node23.html node1.html node79.html --- ## Special methods for attribute access The following methods can be used to change the meaning of attribute access for class instances. --- guido@cwi.nl
1.2
220
https://docs.python.org/{python_version}/python-ref/node24.html
Special methods for sequence and mapping types
--- node26.html node22.html node24.html node1.html node79.html --- ## Special methods for sequence and mapping types --- guido@cwi.nl
1.2
133
https://docs.python.org/{python_version}/python-ref/node25.html
Special methods for sequence types
--- node27.html node22.html node25.html node1.html node79.html --- ## Special methods for sequence types --- guido@cwi.nl
1.2
121
https://docs.python.org/{python_version}/python-ref/node26.html
Special methods for numeric types
--- node28.html node22.html node26.html node1.html node79.html --- ## Special methods for numeric types --- node28.html node22.html node26.html node1.html node79.html --- --- guido@cwi.nl
1.2
187
https://docs.python.org/{python_version}/python-ref/node27.html
Execution model
--- node29.html ref.html node27.html node1.html node79.html --- # Execution model --- - Code blocks, execution frames, and name spaces (node29.html#SECTION00510000000000000000) Exceptions (node30.html#SECTION00520000000000000000) --- guido@cwi.nl
1.2
246
https://docs.python.org/{python_version}/python-ref/node28.html
Code blocks, execution frames, and name spaces
--- node30.html node28.html node28.html node1.html node79.html --- # Code blocks, execution frames, and name spaces A code block is a piece of Python program text that can be executed as a unit, such as a module, a class definition or a function body. Some code blocks (like modules) are executed only once, others (like...
1.2
3,709
https://docs.python.org/{python_version}/python-ref/node29.html
Notation
--- node4.html node2.html node2.html node1.html node79.html --- # Notation The descriptions of lexical analysis and syntax use a modified BNF grammar notation. This uses the following style of definition: ```text name: lc_letter (lc_letter | "_")* lc_letter: "a"..."z" ``` The first line says that a `name` is an `lc_let...
1.2
2,279
https://docs.python.org/{python_version}/python-ref/node3.html
Exceptions
--- node31.html node28.html node29.html node1.html node79.html --- # Exceptions Exceptions are a means of breaking out of the normal flow of control of a code block in order to handle errors or other exceptional conditions. An exception is raised at the point where the error is detected; it may be handled by the surrou...
1.2
1,563
https://docs.python.org/{python_version}/python-ref/node30.html
Expressions and conditions
--- node32.html ref.html node30.html node1.html node79.html --- # Expressions and conditions Note: In this and the following chapters, extended BNF notation will be used to describe syntax, not lexical analysis. This chapter explains the meaning of the elements of expressions and conditions. Conditions are a superset o...
1.2
2,431
https://docs.python.org/{python_version}/python-ref/node31.html
Arithmetic conversions
--- node33.html node31.html node31.html node1.html node79.html --- # Arithmetic conversions When a description of an arithmetic operator below uses the phrase ``the numeric arguments are converted to a common type'', this both means that if either argument is not a number, a `TypeError` exception is raised, and that ot...
1.2
636
https://docs.python.org/{python_version}/python-ref/node32.html
Atoms
--- node34.html node31.html node32.html node1.html node79.html --- # Atoms Atoms are the most basic elements of expressions. Forms enclosed in reverse quotes or in parentheses, brackets or braces are also categorized syntactically as atoms. The syntax for atoms is: ```text atom: identifier | literal | enclosure enclosu...
1.2
767
https://docs.python.org/{python_version}/python-ref/node33.html
Identifiers (Names)
--- node35.html node33.html node33.html node1.html node79.html --- ## Identifiers (Names) An identifier occurring as an atom is a reference to a local, global or built-in name binding. If a name is assigned to anywhere in a code block (even in unreachable code), and is not mentioned in a `global` statement in that code...
1.2
804
https://docs.python.org/{python_version}/python-ref/node34.html
Literals
--- node36.html node33.html node34.html node1.html node79.html --- ## Literals Python knows string and numeric literals: ```text literal: stringliteral | integer | longinteger | floatnumber ``` Evaluation of a literal yields an object of the given type (string, integer, long integer, floating point number) with the giv...
1.2
897
https://docs.python.org/{python_version}/python-ref/node35.html
Parenthesized forms
--- node37.html node33.html node35.html node1.html node79.html --- ## Parenthesized forms A parenthesized form is an optional condition list enclosed in parentheses: ```text parenth_form: "(" [condition_list] ")" ``` A parenthesized condition list yields whatever that condition list yields. An empty pair of parentheses...
1.2
715
https://docs.python.org/{python_version}/python-ref/node36.html
List displays
--- node38.html node33.html node36.html node1.html node79.html --- ## List displays A list display is a possibly empty series of conditions enclosed in square brackets: ```text list_display: "[" [condition_list] "]" ``` A list display yields a new list object. If it has no condition list, the list object has no items. ...
1.2
462
https://docs.python.org/{python_version}/python-ref/node37.html
Dictionary displays
--- node39.html node33.html node37.html node1.html node79.html --- ## Dictionary displays A dictionary display is a possibly empty series of key/datum pairs enclosed in curly braces: ```text dict_display: "{" [key_datum_list] "}" key_datum_list: key_datum ("," key_datum)* [","] key_datum: condition ":" condition ``` A ...
1.2
801
https://docs.python.org/{python_version}/python-ref/node38.html
String conversions
--- node40.html node33.html node38.html node1.html node79.html --- ## String conversions A string conversion is a condition list enclosed in reverse (or backward) quotes: ```text string_conversion: "`" condition_list "`" ``` A string conversion evaluates the contained condition list and converts the resulting object in...
1.2
1,219
https://docs.python.org/{python_version}/python-ref/node39.html
Lexical analysis
--- node5.html ref.html node3.html node1.html node79.html --- # Lexical analysis A Python program is read by a parser. Input to the parser is a stream of tokens, generated by the lexical analyzer. This chapter describes how the lexical analyzer breaks a file into tokens. --- - Line structure (node5.html#SECTION00310000...
1.2
1,072
https://docs.python.org/{python_version}/python-ref/node4.html
Primaries
--- node41.html node31.html node39.html node1.html node79.html --- # Primaries Primaries represent the most tightly bound operations of the language. Their syntax is: ```text primary: atom | attributeref | subscription | slicing | call ``` --- - Attribute references (node41.html#SECTION00631000000000000000) Subscriptio...
1.2
480
https://docs.python.org/{python_version}/python-ref/node40.html
Attribute references
--- node42.html node40.html node40.html node1.html node79.html --- ## Attribute references An attribute reference is a primary followed by a period and a name: ```text attributeref: primary "." identifier ``` The primary must evaluate to an object of a type that supports attribute references, e.g. a module or a list. T...
1.2
658
https://docs.python.org/{python_version}/python-ref/node41.html
Subscriptions
--- node43.html node40.html node41.html node1.html node79.html --- ## Subscriptions A subscription selects an item of a sequence (string, tuple or list) or mapping (dictionary) object: ```text subscription: primary "[" condition "]" ``` The primary must evaluate to an object of a sequence or mapping type. If it is a ma...
1.2
1,005
https://docs.python.org/{python_version}/python-ref/node42.html
Slicings
--- node44.html node40.html node42.html node1.html node79.html --- ## Slicings A slicing (or slice) selects a range of items in a sequence (string, tuple or list) object: ```text slicing: primary "[" [condition] ":" [condition] "]" ``` The primary must evaluate to a sequence object. The lower and upper bound expression...
1.2
785
https://docs.python.org/{python_version}/python-ref/node43.html
Calls
--- node45.html node40.html node43.html node1.html node79.html --- ## Calls A call calls a callable object (e.g. a function) with a possibly empty series of arguments: ```text call: primary "(" [condition_list] ")" ``` The primary must evaluate to a callable object (user-defined functions, built-in functions, methods o...
1.2
671
https://docs.python.org/{python_version}/python-ref/node44.html
Unary arithmetic operations
--- node46.html node31.html node44.html node1.html node79.html --- # Unary arithmetic operations All unary arithmetic (and bit-wise) operations have the same priority: ```text u_expr: primary | "-" u_expr | "+" u_expr | "~" u_expr ``` The unary `"-"` (minus) operator yields the negation of its numeric argument. The una...
1.2
659
https://docs.python.org/{python_version}/python-ref/node45.html
Binary arithmetic operations
--- node47.html node31.html node45.html node1.html node79.html --- # Binary arithmetic operations The binary arithmetic operations have the conventional priority levels. Note that some of these operations also apply to certain non-numeric types. There is no ``power'' operator, so there are only two levels, one for mult...
1.2
2,581
https://docs.python.org/{python_version}/python-ref/node46.html
Shifting operations
--- node48.html node31.html node46.html node1.html node79.html --- # Shifting operations The shifting operations have lower priority than the arithmetic operations: ```text shift_expr: a_expr | shift_expr ( "<<" | ">>" ) a_expr ``` These operators accept plain or long integers as arguments. The arguments are converted ...
1.2
792
https://docs.python.org/{python_version}/python-ref/node47.html
Binary bit-wise operations
--- node49.html node31.html node47.html node1.html node79.html --- # Binary bit-wise operations Each of the three bitwise operations has a different priority level: ```text and_expr: shift_expr | and_expr "&" shift_expr xor_expr: and_expr | xor_expr "^" and_expr or_expr: xor_expr | or_expr "|" xor_expr ``` The `"&"` op...
1.2
782
https://docs.python.org/{python_version}/python-ref/node48.html
Comparisons
--- node50.html node31.html node48.html node1.html node79.html --- # Comparisons Contrary to C, all comparison operations in Python have the same priority, which is lower than that of any arithmetic, shifting or bitwise operation. Also contrary to C, expressions like `a < b < c` have the interpretation that is conventi...
1.2
2,968
https://docs.python.org/{python_version}/python-ref/node49.html
Line structure
--- node6.html node4.html node4.html node1.html node79.html --- # Line structure A Python program is divided in a number of logical lines. The end of a logical line is represented by the token NEWLINE. Statements cannot cross logical line boundaries except where NEWLINE is allowed by the syntax (e.g. between statements...
1.2
651
https://docs.python.org/{python_version}/python-ref/node5.html
Boolean operations
--- node51.html node31.html node49.html node1.html node79.html --- # Boolean operations Boolean operations have the lowest priority of all Python operations: ```text condition: or_test | lambda_form or_test: and_test | or_test "or" and_test and_test: not_test | and_test "and" not_test not_test: comparison | "not" not_t...
1.2
1,940
https://docs.python.org/{python_version}/python-ref/node50.html
Expression lists and condition lists
--- node52.html node31.html node50.html node1.html node79.html --- # Expression lists and condition lists ```text expr_list: or_expr ("," or_expr)* [","] cond_list: condition ("," condition)* [","] ``` The only difference between expression lists and condition lists is the lowest priority of operators that can be used ...
1.2
1,380
https://docs.python.org/{python_version}/python-ref/node51.html
Summary
--- node53.html node31.html node51.html node1.html node79.html --- # Summary The following table summarizes the operator precedences in Python, from lowest precedence (least binding) to highest precedence (most binding). Operators in the same box have the same precedence. Unless the syntax is explicitly given, operator...
1.2
468
https://docs.python.org/{python_version}/python-ref/node52.html
Simple statements
--- node54.html ref.html node52.html node1.html node79.html --- # Simple statements Simple statements are comprised within a single logical line. Several simple statements may occur on a single line separated by semicolons. The syntax for simple statements is: ```text simple_stmt: expression_stmt | assignment_stmt | pa...
1.2
1,305
https://docs.python.org/{python_version}/python-ref/node53.html
Expression statements
--- node55.html node53.html node53.html node1.html node79.html --- # Expression statements Expression statements are used (mostly interactively) to compute and write a value, or (usually) to call a procedure (a function that returns no meaningful result; in Python, procedures return the value `None`): ```text expressio...
1.2
878
https://docs.python.org/{python_version}/python-ref/node54.html
Assignment statements
--- node56.html node53.html node54.html node1.html node79.html --- # Assignment statements Assignment statements are used to (re)bind names to values and to modify attributes or items of mutable objects: ```text assignment_stmt: (target_list "=")+ expression_list target_list: target ("," target)* [","] target: identifi...
1.2
2,304
https://docs.python.org/{python_version}/python-ref/node55.html
The pass statement
--- node57.html node53.html node55.html node1.html node79.html --- # The pass statement ```text pass_stmt: "pass" ``` `pass` is a null operation --- when it is executed, nothing happens. It is useful as a placeholder when a statement is required syntactically, but no code needs to be executed, for example: ```text def ...
1.2
438
https://docs.python.org/{python_version}/python-ref/node56.html
The del statement
--- node58.html node53.html node56.html node1.html node79.html --- # The del statement ```text del_stmt: "del" target_list ``` Deletion is recursively defined very similar to the way assignment is defined. Rather that spelling it out in full details, here are some hints. Deletion of a target list recursively deletes ea...
1.2
812
https://docs.python.org/{python_version}/python-ref/node57.html
The print statement
--- node59.html node53.html node57.html node1.html node79.html --- # The print statement ```text print_stmt: "print" [ condition ("," condition)* [","] ] ``` `print` evaluates each condition in turn and writes the resulting object to standard output (see below). If an object is not a string, it is first converted to a ...
1.2
1,408
https://docs.python.org/{python_version}/python-ref/node58.html
The return statement
--- node60.html node53.html node58.html node1.html node79.html --- # The return statement ```text return_stmt: "return" [condition_list] ``` `return` may only occur syntactically nested in a function definition, not within a nested class definition. If a condition list is present, it is evaluated, else `None` is substi...
1.2
585
https://docs.python.org/{python_version}/python-ref/node59.html
Comments
--- node7.html node5.html node5.html node1.html node79.html --- ## Comments A comment starts with a hash character (`#`) that is not part of a string literal, and ends at the end of the physical line. A comment always signifies the end of the logical line. Comments are ignored by the syntax. --- guido@cwi.nl
1.2
309
https://docs.python.org/{python_version}/python-ref/node6.html
The raise statement
--- node61.html node53.html node59.html node1.html node79.html --- # The raise statement ```text raise_stmt: "raise" condition ["," condition] ``` `raise` evaluates its first condition, which must yield a string, class, or instance object. If there is a second condition, this is evaluated, else `None` is substituted. I...
1.2
835
https://docs.python.org/{python_version}/python-ref/node60.html
The break statement
--- node62.html node53.html node60.html node1.html node79.html --- # The break statement ```text break_stmt: "break" ``` `break` may only occur syntactically nested in a `for` or `while` loop, but not nested in a function or class definition within that loop. It terminates the nearest enclosing loop, skipping the optio...
1.2
608
https://docs.python.org/{python_version}/python-ref/node61.html
The continue statement
--- node63.html node53.html node61.html node1.html node79.html --- # The continue statement ```text continue_stmt: "continue" ``` `continue` may only occur syntactically nested in a `for` or `while` loop, but not nested in a function or class definition or `try` statement within that loop.footnode.html#1125 It continue...
1.2
389
https://docs.python.org/{python_version}/python-ref/node62.html
The import statement
--- node64.html node53.html node62.html node1.html node79.html --- # The import statement ```text import_stmt: "import" identifier ("," identifier)* | "from" identifier "import" identifier ("," identifier)* | "from" identifier "import" "*" ``` Import statements are executed in two steps: (1) find a module, and initiali...
1.2
2,889
https://docs.python.org/{python_version}/python-ref/node63.html
The global statement
--- node65.html node53.html node63.html node1.html node79.html --- # The global statement ```text global_stmt: "global" identifier ("," identifier)* ``` The `global` statement is a declaration which holds for the entire current scope. It means that the listed identifiers are to be interpreted as globals. While using gl...
1.2
970
https://docs.python.org/{python_version}/python-ref/node64.html
The access statement
--- node66.html node53.html node64.html node1.html node79.html --- # The access statement ```text access_stmt: "access" ... ``` This statement will be used in the future to control access to instance and class variables. Currently its syntax and effects are undefined; however the keyword `access` is a reserved word for...
1.2
349
https://docs.python.org/{python_version}/python-ref/node65.html
The exec statement
--- node67.html node53.html node65.html node1.html node79.html --- # The exec statement ```text exec_stmt: "exec" expression ["in" expression ["," expression]] ``` This statement supports dynamic execution of Python code. The first expression should evaluate to either a string, an open file object, or a code object. If...
1.2
1,147
https://docs.python.org/{python_version}/python-ref/node66.html
Compound statements
--- node68.html ref.html node66.html node1.html node79.html --- # Compound statements Compound statements contain (groups of) other statements; they affect or control the execution of those other statements in some way. In general, compound statements span multiple lines, although in simple incarnations a whole compoun...
1.2
2,723
https://docs.python.org/{python_version}/python-ref/node67.html
The if statement
--- node69.html node67.html node67.html node1.html node79.html --- # The if statement The `if` statement is used for conditional execution: ```text if_stmt: "if" condition ":" suite ("elif" condition ":" suite)* ["else" ":" suite] ``` It selects exactly one of the suites by evaluating the conditions one by one until on...
1.2
613
https://docs.python.org/{python_version}/python-ref/node68.html
The while statement
--- node70.html node67.html node68.html node1.html node79.html --- # The while statement The `while` statement is used for repeated execution as long as a condition is true: ```text while_stmt: "while" condition ":" suite ["else" ":" suite] ``` This repeatedly tests the condition and, if it is true, executes the first ...
1.2
725
https://docs.python.org/{python_version}/python-ref/node69.html
Explicit line joining
--- node8.html node5.html node6.html node1.html node79.html --- ## Explicit line joining Two or more physical lines may be joined into logical lines using backslash characters (`\`), as follows: when a physical line ends in a backslash that is not part of a string literal or comment, it is joined with the following for...
1.2
761
https://docs.python.org/{python_version}/python-ref/node7.html
The for statement
--- node71.html node67.html node69.html node1.html node79.html --- # The for statement The `for` statement is used to iterate over the elements of a sequence (string, tuple or list): ```text for_stmt: "for" target_list "in" condition_list ":" suite ["else" ":" suite] ``` The condition list is evaluated once; it should ...
1.2
2,355
https://docs.python.org/{python_version}/python-ref/node70.html
The try statement
--- node72.html node67.html node70.html node1.html node79.html --- # The try statement The `try` statement specifies exception handlers and/or cleanup code for a group of statements: ```text try_stmt: try_exc_stmt | try_fin_stmt try_exc_stmt: "try" ":" suite ("except" [condition ["," target]] ":" suite)+ ["else" ":" su...
1.2
3,751
https://docs.python.org/{python_version}/python-ref/node71.html
Function definitions
--- node73.html node67.html node71.html node1.html node79.html --- # Function definitions A function definition defines a user-defined function object (see section node21.html#types): ```text funcdef: "def" funcname "(" [parameter_list] ")" ":" suite parameter_list: (defparameter ",")* ("*" identifier | defparameter ["...
1.2
3,795
https://docs.python.org/{python_version}/python-ref/node72.html
Class definitions
--- node74.html node67.html node72.html node1.html node79.html --- # Class definitions A class definition defines a class object (see section node21.html#types): ```text classdef: "class" classname [inheritance] ":" suite inheritance: "(" [condition_list] ")" classname: identifier ``` A class definition is an executabl...
1.2
1,031
https://docs.python.org/{python_version}/python-ref/node73.html
Top-level components
--- node75.html ref.html node73.html node1.html node79.html --- # Top-level components The Python interpreter can get its input from a number of sources: from a script passed to it as standard input or as program argument, typed in interactively, from a module source file, etc. This chapter gives the syntax used in the...
1.2
591
https://docs.python.org/{python_version}/python-ref/node74.html
Complete Python programs
--- node76.html node74.html node74.html node1.html node79.html --- # Complete Python programs While a language specification need not prescribe how the language interpreter is invoked, it is useful to have a notion of a complete Python program. A complete Python program is executed in a minimally initialized environmen...
1.2
1,388
https://docs.python.org/{python_version}/python-ref/node75.html
File input
--- node77.html node74.html node75.html node1.html node79.html --- # File input All input read from non-interactive files has the same form: ```text file_input: (NEWLINE | statement)* ``` This syntax is used in the following situations: - when parsing a complete Python program (from a file or from a string); when parsi...
1.2
403
https://docs.python.org/{python_version}/python-ref/node76.html
Interactive input
--- node78.html node74.html node76.html node1.html node79.html --- # Interactive input Input in interactive mode is parsed using the following grammar: ```text interactive_input: [stmt_list] NEWLINE | compound_stmt NEWLINE ``` Note that a (top-level) compound statement must be followed by a blank line in interactive mo...
1.2
403
https://docs.python.org/{python_version}/python-ref/node77.html
Expression input
--- node79.html node74.html node77.html node1.html node79.html --- # Expression input There are two forms of expression input. Both ignore leading whitespace. The string argument to `eval()` must have the following form: ```text eval_input: condition_list NEWLINE* ``` The input line read by `input()` must have the foll...
1.2
543
https://docs.python.org/{python_version}/python-ref/node78.html
Index
--- node80.html ref.html node78.html node1.html --- ## Index --- guido@cwi.nl
1.2
77
https://docs.python.org/{python_version}/python-ref/node79.html
Implicit line joining
--- node9.html node5.html node7.html node1.html node79.html --- ## Implicit line joining Expressions in parentheses, square brackets or curly braces can be split over more than one physical line without using backslashes. For example: ```text month_names = ['Januari', 'Februari', 'Maart', # These are the 'April', 'Mei'...
1.2
608
https://docs.python.org/{python_version}/python-ref/node8.html
About this document ...
--- ref.html node79.html node1.html node79.html --- # About this document ... Python Reference Manual This document was generated using the LaTeX2HTML (http://cbl.leeds.ac.uk/nikos/tex2html/doc/latex2html/latex2html.html) translator Version 95.1 (Fri Jan 20 1995) Copyright © 1993, 1994, Nikos Drakos (http://cbl.leeds.a...
1.2
594
https://docs.python.org/{python_version}/python-ref/node80.html
Blank lines
--- node10.html node5.html node8.html node1.html node79.html --- ## Blank lines A logical line that contains only spaces, tabs, and possibly a comment, is ignored (i.e., no NEWLINE token is generated), except that during interactive input of statements, an entirely blank logical line terminates a multi-line statement. ...
1.2
336
https://docs.python.org/{python_version}/python-ref/node9.html
Python Reference Manual
--- node1.html node1.html node79.html --- # Python Reference Manual Guido van Rossum Dept. AA, CWI, P.O. Box 94079 1090 GB Amsterdam, The Netherlands E-mail: guido@cwi.nl 10 April 1995 Release 1.2 Copyright © 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, The Netherlands. All Rights Reserved Permission to use,...
1.2
7,344
https://docs.python.org/{python_version}/python-ref/ref.html
Footnotes
guido@cwi.nl
1.2
12
https://docs.python.org/{python_version}/python-tut/footnode.html
Contents
--- node2.html tut.html tut.html --- ## Contents - Whetting Your Appetite (node2.html#SECTION00200000000000000000) - Where From Here (node3.html#SECTION00210000000000000000) Using the Python Interpreter (node4.html#SECTION00300000000000000000) - Invoking the Interpreter (node5.html#SECTION00310000000000000000) - Argume...
1.2
6,590
https://docs.python.org/{python_version}/python-tut/node1.html
The Module Search Path
--- node11.html node8.html node9.html node1.html --- ## The Module Search Path When a module named spam is imported, the interpreter searches for a file named spam.py in the list of directories specified by the environment variable PYTHONPATH. It has the same syntax as the Unix shell variable PATH, i.e., a list of colo...
1.2
838
https://docs.python.org/{python_version}/python-tut/node10.html
Python and the World-Wide Web
--- node101.html node91.html node99.html node1.html --- # Python and the World-Wide Web There is a growing number of modules available for writing WWW tools. The previous release already sported modules `gopherlib`, `ftplib`, `httplib` and `urllib` (which unifies the other three) for accessing data through the commones...
1.2
1,103
https://docs.python.org/{python_version}/python-tut/node100.html
Miscellaneous
--- node102.html node91.html node100.html node1.html --- # Miscellaneous - The `socket` module now exports all the needed constants used for socket operations, such as `SO_BROADCAST`. The functions `popen()` and `fdopen()` in the `os` module now follow the pattern of the built-in function `open()`: the default mode arg...
1.2
524
https://docs.python.org/{python_version}/python-tut/node101.html
About this document ...
--- tut.html node101.html node1.html --- # About this document ... Python Tutorial This document was generated using the LaTeX2HTML (http://cbl.leeds.ac.uk/nikos/tex2html/doc/latex2html/latex2html.html) translator Version 95.1 (Fri Jan 20 1995) Copyright © 1993, 1994, Nikos Drakos (http://cbl.leeds.ac.uk/nikos/personal...
1.2
575
https://docs.python.org/{python_version}/python-tut/node102.html
``Compiled'' Python files
--- node12.html node8.html node10.html node1.html --- ## ``Compiled'' Python files As an important speed-up of the start-up time for short programs that use a lot of standard modules, if a file called spam.pyc exists in the directory where spam.py is found, this is assumed to contain an already-``compiled'' version of ...
1.2
779
https://docs.python.org/{python_version}/python-tut/node11.html
Executable Python scripts
--- node13.html node8.html node11.html node1.html --- ## Executable Python scripts On BSD'ish Unix systems, Python scripts can be made directly executable, like shell scripts, by putting the line ```text #! /usr/local/bin/python ``` (assuming that's the name of the interpreter) at the beginning of the script and giving...
1.2
419
https://docs.python.org/{python_version}/python-tut/node12.html
The Interactive Startup File
--- node14.html node8.html node12.html node1.html --- ## The Interactive Startup File When you use Python interactively, it is frequently handy to have some standard commands executed every time the interpreter is started. You can do this by setting an environment variable named PYTHONSTARTUP to the name of a file cont...
1.2
1,202
https://docs.python.org/{python_version}/python-tut/node13.html
Interactive Input Editing and History Substitution
--- node15.html node4.html node13.html node1.html --- # Interactive Input Editing and History Substitution Some versions of the Python interpreter support editing of the current input line and history substitution, similar to facilities found in the Korn shell and the GNU Bash shell. This is implemented using the GNU R...
1.2
1,012
https://docs.python.org/{python_version}/python-tut/node14.html
Line Editing
--- node16.html node14.html node14.html node1.html --- ## Line Editing If supported, input line editing is active whenever the interpreter prints a primary or secondary prompt. The current line can be edited using the conventional Emacs control characters. The most important of these are: C-A (Control-A) moves the curs...
1.2
727
https://docs.python.org/{python_version}/python-tut/node15.html
History Substitution
--- node17.html node14.html node15.html node1.html --- ## History Substitution History substitution works as follows. All non-empty input lines issued are saved in a history buffer, and when a new prompt is given you are positioned on a new line at the bottom of this buffer. C-P moves one line up (back) in the history ...
1.2
620
https://docs.python.org/{python_version}/python-tut/node16.html
Key Bindings
--- node18.html node14.html node16.html node1.html --- ## Key Bindings The key bindings and some other parameters of the Readline library can be customized by placing commands in an initialization file called $HOME/.inputrc. Key bindings have the form ```text key-name: function-name ``` or ```text "string": function-na...
1.2
937
https://docs.python.org/{python_version}/python-tut/node17.html
Commentary
--- node19.html node14.html node17.html node1.html --- ## Commentary This facility is an enormous step forward compared to previous versions of the interpreter; however, some wishes are left: It would be nice if the proper indentation were suggested on continuation lines (the parser knows if an indent token is required...
1.2
504
https://docs.python.org/{python_version}/python-tut/node18.html
An Informal Introduction to Python
--- node20.html tut.html node18.html node1.html --- # An Informal Introduction to Python In the following examples, input and output are distinguished by the presence or absence of prompts (>>> and ...): to repeat the example, you must type everything after the prompt, when the prompt appears; lines that do not begin w...
1.2
840
https://docs.python.org/{python_version}/python-tut/node19.html
Whetting Your Appetite
--- node3.html tut.html node1.html node1.html --- # Whetting Your Appetite If you ever wrote a large shell script, you probably know this feeling: you'd love to add yet another feature, but it's already so slow, and so big, and so complicated; or the feature involves a system call or other function that is only accessi...
1.2
3,190
https://docs.python.org/{python_version}/python-tut/node2.html
Using Python as a Calculator
--- node21.html node19.html node19.html node1.html --- # Using Python as a Calculator Let's try some simple Python commands. Start the interpreter and wait for the primary prompt, >>>. (It shouldn't take long.) --- - Numbers (node21.html#SECTION00411000000000000000) Strings (node22.html#SECTION00412000000000000000) Lis...
1.2
381
https://docs.python.org/{python_version}/python-tut/node20.html
Numbers
--- node22.html node20.html node20.html node1.html --- ## Numbers The interpreter acts as a simple calculator: you can type an expression at it and it will write the value. Expression syntax is straightforward: the operators +, -, * and / work just like in most other languages (e.g., Pascal or C); parentheses can be us...
1.2
1,067
https://docs.python.org/{python_version}/python-tut/node21.html
Strings
--- node23.html node20.html node21.html node1.html --- ## Strings Besides numbers, Python can also manipulate strings, enclosed in single quotes or double quotes: ```text >>> 'spam eggs' 'spam eggs' >>> 'doesn\'t' "doesn't" >>> "doesn't" "doesn't" >>> '"Yes," he said.' '"Yes," he said.' >>> "\"Yes,\" he said." '"Yes," ...
1.2
3,638
https://docs.python.org/{python_version}/python-tut/node22.html