Python Strings
Python Strings
What are strings?
In python, anything that you enclose between single or double quotation marks is considered a string. A string is essentially a sequence or array of textual data.
Strings are used when working with Unicode characters.
Example:
Output:
Note: It does not matter whether you enclose your strings in single or double quotes, the output remains the same.
Sometimes, the user might need to put quotation marks in between the strings. Example, consider the sentence: He said, “I want to eat an apple”.
How will you print this statement in python?
Wrong way ❌
Output:
Right way ✔️
Output:
What if you want to write multiline strings?
Sometimes the programmer might want to include a note, or a set of instructions, or just might want to explain a piece of code. Although this might be done using multiline comments, the programmer may want to display this in the execution of programmer. This is done using multiline strings.
Example:
Output: