TOCPython Draft for Information Only
ContentPython program
Python programA Python program is read by a parser. Input to the parser is a stream of tokens, generated by the lexical analyzer.Python Language StructureA Python program can be divided into a number of script lines.Line StructureThere are two kinds of line structures.Logical LinesLogical line is a complete Python sentence. The end of a logical line is represented by the tokenPhysical linesA physical line is a sequence of characters terminated by an end-of-line sequence. In source files and strings, any of the standard platform line termination sequences can be used - the Unix form using ASCII LF (linefeed), the Windows form using the ASCII sequence CR LF (return followed by linefeed), or the old Macintosh form using the ASCII CR (return) character. All of these forms can be used equally, regardless of platform. The end of input also serves as an implicit terminator for the final physical line. When embedding Python, source code strings should be passed to Python APIs using the standard C conventions for newline characters (theLine JoiningExplicit Line JoiningTwo or more physical lines may be joined into logical lines using backslash charactersif 1900 < year < 2100 and 1 <= month <= 12 \
and 1 <= day <= 31 and 0 <= hour < 24 \
and 0 <= minute < 60 and 0 <= second < 60: # Looks like a valid date
return 1
A line ending in a backslash cannot carry a comment. A backslash does not continue a comment. A backslash does not continue a token except for string literals (i.e. tokens other than string literals cannot be split across physical lines using a backslash). A backslash is illegal elsewhere on a line outside a string literal.
Implicit Line JoiningExpressions in parentheses, square brackets or curly braces can be split over more than one physical line without using backslasher. For example:month_names = ['Januari', 'Februari', 'Maart', # These are the
'April', 'Mei', 'Juni', # Dutch names
'Juli', 'Augustus', 'September', # for the months
'Oktober', 'November', 'December'] # of the year
Implicitly continued lines can carry comments. The indentation of the continuation lines is not important. Blank continuation lines are allowed. There is no Multiple Logical Line in One Physical LineIf more than one logical line is specified in a physical line, then a semicolonBlank LinesA logical line that contains only spaces, tabs, formfeeds and possibly a comment, is ignored (i.e., noWhitespace Between TokensExcept at the beginning of a logical line or in string literals, the whitespace characters space, tab and formfeed can be used interchangeably to separater tokens. Whitespace is needed between two tokens only if their concatenation could otherwise be interpreted as a different token (e.g., ab is one token, but a b is two tokens).IndentationIndentation is whitespaces at the beginning of the line. Indentation is important in Python. Leading whitespace, tabs and spaces, at the beginning of the logical line are used to determine the indentation level of the logical line which in turn is used to determine the grouping of statements. A group of statements that have to go together are marked by an indentation level. These statements are referred to as a block of statements.Other TokensBesidesSource and Reference©sideway ID: 200501102 Last Updated: 5/11/2020 Revision: 0 Latest Updated Links
|
Home 5 Business Management HBR 3 Information Recreation Hobbies 8 Culture Chinese 1097 English 339 Reference 79 Computer Hardware 249 Software Application 213 Digitization 32 Latex 52 Manim 205 KB 1 Numeric 19 Programming Web 289 Unicode 504 HTML 66 CSS 65 SVG 46 ASP.NET 270 OS 429 DeskTop 7 Python 72 Knowledge Mathematics Formulas 8 Set 1 Logic 1 Algebra 84 Number Theory 206 Trigonometry 31 Geometry 34 Calculus 67 Engineering Tables 8 Mechanical Rigid Bodies Statics 92 Dynamics 37 Fluid 5 Control Acoustics 19 Natural Sciences Matter 1 Electric 27 Biology 1 |
Copyright © 2000-2024 Sideway . All rights reserved Disclaimers last modified on 06 September 2019