Keywords, Identifiers, Geometry Concepts, etc.
The Appendix page lists useful information regarding Keywords, Identifiers, Comparison Operators, Decimal and Binary systems, etc.
Appendix – Python 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. All characters after the hash character (#) and up to the end of the physical line are part of the comment; the Python interpreter ignores them.
Here are some examples of comments.
>>> # This is my first Python program.
In the above example, all characters from the hash character sign to the end of the line are ignored by Python.
You can type a comment on the same line after a statement or expression as below.
>>> print(“My name is Robert.”) # Another comment.
Multi-line comments: If your comment is long, you can do it on multiple lines using triple single quotes (‘’’). The following triple-quoted string is ignored by the Python interpreter and is treated as a comment:
>>> ‘’’ This is
>>> a multi-line
>>> comment.”’
Appendix – Quotations in Python
Python accepts single (‘), double (“), and triple (”’ or “””) quotes to denote string literals, as long as the same type of quote starts and ends the string.
If your string is long, you can use triple quotes to type the string across multiple lines.
Below is an example of string literals with a single quote (‘), double quote (“), and triple quote.
>>> literal1 = ‘literal using single quotes’
>>> literal2 = “literal using double quotes”
>>> multilineLiteral = ‘’’This literal is composed of
multiple lines.’’’
Python Identifiers
A Python identifier is a name used to identify a variable, function, class, module, or other object. An identifier starts with a letter A to Z or a to z or an underscore (_) followed by zero or more letters, underscores, and digits (0 to 9). Python does not allow punctuation characters such as @, $, and % within identifiers. Identifiers are case sensitive, therefore, an identifier name such as ‘abc’ is different from ‘Abc’ or ‘aBc’ etc.
Naming conventions for Python identifiers:
- Class names start with an uppercase letter. All other identifiers start with a lowercase letter.
- Starting an identifier with a single leading underscore indicates that the identifier is private.
- Starting an identifier with two leading underscores indicates a strongly private identifier.
- If the identifier also ends with two trailing underscores, the identifier is a language-defined special name.
Source: https://docs.python.org/3/reference/lexical_analysis.html#identifiers
Python Keywords
Python uses the following identifiers as reserved words, or keywords, You cannot use the keywords as user-defined identifiers, constants, or variables. All Python keywords are lowercase only. They must be spelled exactly as written here:
and | Exec | not |
assert | Finally | or |
break | For | pass |
class | From | |
continue | Global | raise |
def | If | return |
del | Import | try |
elif | In | while |
else | Is | with |
except | Lambda | yield |
Python Comparison Operators
The following is a list of Python Comparison Operators.
https://docs.python.org/3/reference/lexical_analysis.html#operators
+ | – | * | ** | / | // | % | @ |
<< | >> | & | | | ^ | ~ | := | |
< | > | <= | >= | == | != |
Python Built-in Functions
Python distribution comes with the following built-in functions. For details of these functions, refer to this link.
Source: https://docs.python.org/3/library/functions.html#functions
ASCII Code Tables
The table shows how the computer stores the numbers, alphabets, and symbols as 8-bit codes.
Decimal = Decimal Value
Char = Character
DECIMAL | Char | Decimal | Char | Decimal | Char | Decimal | Char | |
0 | NUL | (null) | 32 | SPACE | 64 | @ | 96 | ` |
1 | SOH | (start of heading) | 33 | ! | 65 | A | 97 | a |
2 | STX | (start of text) | 34 | “ | 66 | B | 98 | b |
3 | ETX | (end of text) | 35 | # | 67 | C | 99 | c |
4 | EOT | (end of transmission) | 36 | $ | 68 | D | 100 | d |
5 | ENQ | (enquiry) | 37 | % | 69 | E | 101 | e |
6 | ACK | (acknowledge) | 38 | & | 70 | F | 102 | f |
7 | BEL | (bell) | 39 | ‘ | 71 | G | 103 | g |
8 | BS | (backspace) | 40 | ( | 72 | H | 104 | h |
9 | TAB | (horizontal tab) | 41 | ) | 73 | I | 105 | i |
10 | LF | (NL line feed, new line) | 42 | * | 74 | J | 106 | j |
11 | VT | (vertical tab) | 43 | + | 75 | K | 107 | k |
12 | FF | (NP form feed, new page) | 44 | , | 76 | L | 108 | l |
13 | CR | (carriage return) | 45 | – | 77 | M | 109 | m |
14 | SO | (shift out) | 46 | . | 78 | N | 110 | n |
15 | SI | (shift in) | 47 | / | 79 | O | 111 | o |
16 | DLE | (data link escape) | 48 | 0 | 80 | P | 112 | p |
17 | DC1 | (device control 1) | 49 | 1 | 81 | Q | 113 | q |
18 | DC2 | (device control 2) | 50 | 2 | 82 | R | 114 | r |
19 | DC3 | (device control 3) | 51 | 3 | 83 | S | 115 | s |
20 | DC4 | (device control 4) | 52 | 4 | 84 | T | 116 | t |
21 | NAK | (negative acknowledge) | 53 | 5 | 85 | U | 117 | u |
22 | SYN | (synchronous idle) | 54 | 6 | 86 | V | 118 | v |
23 | ETB | (end of trans. block) | 55 | 7 | 87 | W | 119 | w |
24 | CAN | (cancel) | 56 | 8 | 88 | X | 120 | x |
25 | EM | (end of medium) | 57 | 9 | 89 | Y | 121 | y |
26 | SUB | (substitute) | 58 | : | 90 | Z | 122 | z |
27 | ESC | (escape) | 59 | ; | 91 | [ | 123 | { |
28 | FS | (file separator) | 60 | < | 92 | \ | 124 | | |
29 | GS | (group separator) | 61 | = | 93 | ] | 125 | } |
30 | RS | (record separator) | 62 | > | 94 | ^ | 126 | ~ |
31 | US | (unit separator) | 63 | ? | 95 | _ | 127 | DEL |
Example 1:
Character ‘5’ has the integer value 53.
Character ‘0’ has the integer value 48.
String arithmetic ‘5’ – ‘0’ will evaluate to 53 – 48, or the int 5.
Example 2:
Char ‘a’ = decimal 97
Char ‘A’ = decimal 65
‘a’ – ‘A’ will evaluate to 97 – 65 = 32
c = ‘B’+32 = 66 + 32 = 98, which is the ASCII code for ‘b’. Therefore, variable ‘c’ stores character ‘b’.