Classwork 94226
Classwork 94226
language
PART-II
1|Page
III. Literals:- Literals or constants are data items that are fixed values. Several kinds of literals are
Eg: ′ a ′ , ″ a ″ , ′ xy ′ , ″ 123 ″
Python allows certain non graphic characters in string values. Non-graphic characters are those
characters that cannot be typed directly from the keyboard . They are known as escape sequence. These
characters are represented by a backslash(\) followed by one or more characters
\b Backspace
\t Horizontal tab
\v Vertical tab
\a Alert bell
❑ Multiline Strings
• Single Line Strings:- The strings that are created by enclosing in single quotes or double quotes
(′ ′ or ″ ″ ) that are terminated in a single line are Single Line Strings. Python by default
creates single line strings. So if at the end of a string if there is no closing quotation for an open
quotation it reports an error.
″ this is my book ″
• Multiline Strings:- The strings that are created by enclosing in single or double quotes
which can be in multiple lines are Multiline Strings. Multiline strings can be created in 2
ways
2|Page
❖ By adding a backslash at the end of normal single/double quote strings. (Add a backslash
before pressing the enter key).Do not intent when continuing in the next line after
pressing \.
Language ″
Text= ″ Programming\
enter key
Eg:Text = ′ ′ ′ Welcome
to
python ′ ′ ′
OR
Text= ″ ″ ″ Welcome
to
Python
Programming ″ ″ ″
Size of Strings
The size of the string is determined as the count of the number of characters in the string.
1. ″ Hello ″-→ 5
character )
4. Seema\’s Pen- → 11
For Multiline Strings ,the EOL(End Of Line) character at the end of the line is counted.
3|Page
1. Text= ″ Python
Programming ″→ 18
2. Text= ″ a
c″→5
For Multiline strings created with backslash , the backslash is not counted
Text= ″ Python\
Programming ″ → 17
Text= ″ a\
b\
c″→3
Text= ′ Welcome′
len(Text)
Output-7
len(A)
Output-28
a. Integer Literal
c. Complex Literal
a. Integer literal:- They are reffered as integers or int .They represent +ve or –ve
numbers without any decimal point. A number with no sign is considered as an +ve
i. Decimal Integer Literal:- An integer literal consisting of numbers 0 to 9 which does not
Eg: 1234,789,304
ii. Octal Integer Literal:- It is an integer literal consisting of numbers 0 to 7 which starts with
0X
Eg: 0x179,0XAF3,0x79C
b. Floating point literal:- They are also called as real literal. They are numbers having a fractional part.
Fractional Form:- A real literal in fractional form consist of signed or unsigned digits including a
decimal point between the numbers . It should have at least one digit either before or after the
decimal point
Exponent Part
2.5 E 5
Mantissa Part
5|Page
The Mantissa part can be either a real or integer constant. It is followed by the letter E or e .
0.00625 X 10 -4 →0.00625 e -4
c. Complex Literal :- They are numbers in the form of a + ib where a and b are floating point
values and i represents √-1 which is an imaginary number. a is the real part and b is the imaginary part
3. Boolean Literal:- A Boolean literal is used to represent one of the two values True or False.
4.Special Literal None:-The None literal is used to represent the absence of a value. The value None
means “There is Nothing”. It does not display anything when asked to display the value of a variable
containing None
i. 23.789
ii. 23789
iii. True
iv. ‘True’
v. O124
vi. OxA4F6
vii. None
i. ‘\a’
ii. “\a”
iii. “It’s”
6|Page
iv. xy\
yz”
v. “ “ “ xy
yz” ” ”
1. 23.56 X106
2. 0.00567
3. 12.678
4.1356
5. 1.67 X 10 7
7|Page