Tools, FAQ, Tutorials:
'str' Literals and Conversions
How to specify "str" values in Python code?
✍: FYIcenter.com
"str" values can be specified using "str" literals or the str() conversion function as shown in this tutorial:
1. "str" literals in double quotes as shown below:
>>> "FYIcenter.com" 'FYIcenter.com' >>> "He says: \"No\"" 'He says: "No"' >>> "He says:\n\"No\"" 'He says:\n"No"'
2. "str" literals in single quotes as shown below:
>>> 'FYIcenter.com' 'FYIcenter.com' >>> 'He says: "No"' 'He says: "No"' >>> 'He says:\n"No"' 'He says:\n"No"'
3. "str" literals in triple quotes that allows you to express strings in multiple lines as shown below:
>>> """Spanning ... multiple ... lines""" 'Spanning\nmultiple\nlines' >>> '''Spanning ... multiple ... lines''' 'Spanning\nmultiple\nlines'
4. "str" literals with "\" escape sequences as shown below:
>>> "Name\t\x41ge\n" 'Name\tAge\n' >>> "Name\t\u0041ge\n" 'Name\tAge\n'
5. str() function converting other data types to "str":
>>> str(1234) '1234' >>> str(3.14159) '3.14159' >>> str(True) 'True'
⇒ 'bytes' Literals and Conversions
⇐ Python Built-in Structured Data Types
2018-04-07, 1314🔥, 0💬
Popular Posts:
Can You Add Values to an Array without Keys in PHP? Can You Add Values to an Array with a Key? The a...
How to create the Hello-3.0.epub package? I have all required files to create Hello-3.0.epub. To cre...
How to access Query String parameters from "context.Request.Url.Que ry"object in Azure API Policy? Q...
How to use the "find-and-replace" Policy Statement for an Azure API service operation? The "find-and...
What is EPUB 2.0 Metadata "dc:publisher" and "dc:rights" elements? EPUB 2.0 Metadata "dc:publisher" ...