How to define strings in Python

A string is identified through the use of quotation marks. In the definition of a string in Python both single and double quotes can be used: “string”.

This double possibility of using the identifier allows us to include a type of quotation marks in a string enclosed by quotation marks of the other type, which is indispensable for example in the use of the apostrophe.

To better understand what has been said, let’s see an example:

>>> print “String containing the apostrophe …”

How to define strings in Python

Let’s see in detail how many ways it is possible to define a string:

  •    With single quotes: ‘String in Python!’
  •    With double quotes: “String in Python!”
  •    Escape sequences: “Type the command \” ls \ “”
  •    Through the use of transformation functions from other types of values: str (1111), str (11.11), str (11.1 + 1j)
  •    Finally the multiline strings with the adoption of three quotes (single or double).

To deep this argument:

Leave a Reply

Your email address will not be published. Required fields are marked *