Literals (Literals), lesson, page 724621
https://www.purl.org/stefan_ram/pub/literals_python (permalink) is the canonical URI of this page.
Stefan Ram
Python Course

Literals in Python 

₍stɚ₎ str literals

A str literal indicates a str value. It can be written with quotation marks or apostrophes.

Railroad diagram (simplified)

str literal
.-. .-.
|-|--->( " )--->.--------------------.--->( " )--->|-|
'-' ^ | '-'
| .-----------. |
'---| character |<---'
'-----------'

str literal
.-. .-.
|-|--->( ' )--->.--------------------.--->( ' )--->|-|
'-' ^ | '-'
| .-----------. |
'---| character |<---'
'-----------'

A str literal
'Hallo, Welt'
A str literal
"Hallo, Welt"
Evaluation of the expression »"abc"« with subsequent output of a text representation of the object obtained
                    evaluation        text representation
"abc" ---------------------> abc ---------------------> 'abc'
expression object text representation

Refactors

Transforming the (source code of a )program that meets its requirements is transformed to another (source code of a )program that also meets the same requirements is called a refactor.

Program 0
"abc"
Program 1
'abc'

Decimal Numerals

If a literal consists only of digits, the quotation marks or apostrophes can be omitted.

Input of an expression and output of a text representation of its value
32767
32767

To improve readability, the underscore can be used between digits without changing the value of the literal.

Input of an expression and output of a text representation of its value
32_767
32767

Hexadecimal numerals

In the hexadecimal system, the letters starting from »A« stand for the values starting from ten, and the value of second digit from the right is multiplied by 16. So »B0« means ‹ 11×16 + 0 ›.

Input of an expression and output of a text representation of its value
0xB0
176

Decimal places

Decimal places can be delimited by a point ».«. The value is not always displayed exactly. Deviations can occur, especially in the last few digits.

Input of an expression and output of a text representation of its value
3.1415926535897932
3.141592653589793

About this page, Impressum  |   Form for messages to the publisher regarding this page  |   "ram@zedat.fu-berlin.de" (without the quotation marks) is the email address of Stefan Ram.   |   A link to the start page of Stefan Ram appears at the top of this page behind the text "Stefan Ram".)  |   Copyright 1998-2020 Stefan Ram, Berlin. All rights reserved. This page is a publication by Stefan Ram. relevant keywords describing this page: Stefan Ram Berlin slrprd slrprd stefanramberlin spellched stefanram724621 stefan_ram:724621 Literals Stefan Ram, Berlin, and, or, near, uni, online, slrprd, slrprdqxx, slrprddoc, slrprd724621, slrprddef724621, PbclevtugFgrsnaEnz Explanation, description, info, information, note,

Copyright 1998-2020 Stefan Ram, Berlin. All rights reserved. This page is a publication by Stefan Ram.
https://www.purl.org/stefan_ram/pub/literals_python