Send
Close Add comments:
(status displays here)
Got it! This site "robinsnyder.com" uses cookies. You consent to this by clicking on "Got it!" or by continuing to use this website. Note: This appears on each machine/browser from which this site is accessed.
Python: Literals
1. Literal
The English word "literal" comes from the Latin word for "letter".
2. Literal
A literal is an expressly written entity.
A literal value literally expresses a value.
The word "entity" is a nice way to say "thing" or "something".
3. Entity
The word
entity means thing, as in an instance of something such as an object.
A computer
string is a sequence of entities.
A computer string is not part of a rope.
4. Strings
A
string is a sequence of entities of the same type.
A bit string is a sequence of bits.
A byte string is a sequence of bytes.
A character string is a sequence of characters.
Whenever the type of string is not specified, the word
string usually means a text string or sequence of characters.
What is a character string? Give a specific example of a character string.
5. Delimit
The English word "delimit" means to mark the boundaries.
Double quote characters, ASCII #34, are used to delimit (the boundaries) of a string literal.
Single quote characters, ASCII #39, are used to delimit (the boundaries) of a character literal.
6. Strings and characters
A (character) string is made up of zero or more characters. An empty string has no characters.
String literals are delimited by the double quote character.
Character literals are single characters delimited by single quote characters.
Note: Lua has some other ways of delimiting strings (not covered here).
So a string literal is zero or more characters delimited by the double quote character while a character literal is exactly one character delimited by the single quote character.
7. Floats and integers
An integer is a number without a fractional part.
A number, with an optional fractional part, represents an approximation to a mathematical real number.
Such numbers are called floating point approximations, or, for short, a float.
8. Literals
If a literal is to represent or be computed with an integer, write it as an integer literal.
40
If a literal is to represent or be computed with a float/double, write it as a float/double literal by including the decimal point.
40.0
9. End of page