Literals in python
Literals in python
By,
Mrs.B.VIJAYALAKSHMI,
Assistant Professor,
Department Of Computer Science.
Literals in Python
• A numeric literal is a literal containing only the digits 0–9, a sign character (1
or 2) and a possible decimal point.
• Commas are never used in numeric literals.
There are 3 Numerical types
• integers : positive or negative whole numbers with no decimal points
( Eg : 2, -6, 3, 5, 7 )
• Floating point : Consists of Fractional part. ( Eg. 1.4, 5.6 )
• Complex numbers
Limits of Range in floating point representation
• Single Quote ‘ ‘
• Double Quote “ “
• Triple Quote ‘’’ ‘’’
Represent the string either in ‘ PYTHON ’ or “ PYTHON “
Triple Quote is used to represent “ multi line string “
Eg :
‘’’ WELCOME TO
PYTHON PROGRAMMING ‘’’
Number Formatting
• The built-in format function can be used to produce a value containing a
specific number of decimal places.
Syntax :
format(value, format_specifier)
where value is the value to be displayed
format_specifier can contain specific number of
decimal places.
Eg: format(12/5, '.2f') -> '2.40'
format(5/7, '.2f') -> '0.71‘
format specifier '.2f' rounds the result to two decimal places.
String Formatting
EXAMPLE :
>>>print('Hello\nJennifer Smith')
O/P:
Hello
Jennifer Smith