![]() ![]() To go to a new line in Python, you can use the newline character \n within a string. Going to a new line is not possible by putting a bunch of pre-determined spaces in python. In Python, the backslash is used as an escape character, so if you want to print an actual backslash, you need to use a double backslash \ or a raw string with an ‘r’ prefix like r"\" 3. To use a backslash inside a string, a backslash must be written as usual before the backslash is printed.Įxample of Backslash: print(" Printed string is \\") We define a new string variable newStr and use string concatenation to join the sliced parts of the original string and the single quote. Then, we use string slicing to insert a single quote before the word "string". In the above program, we first define a string variable string. # Insert a single quote before the word "string" To use a single quote inside a string, a backslash followed by a single quote makes it valid to be used in a statement.Įxample of Simple Quote: string = "This is a string" Some of the escape sequences that are widely used by programmers are as follows:- 1. ![]() We already discussed in the previous section about inserting a new line, similarly in python, inserting double quotes inside a string can result in an error so using a backslash before the character can make it work. ![]() How to Use Escape SequencesĮscape sequences in python can be used by placing a backslash character and then the character that needs to be inserted. To insert a new line, an escape sequence can be used for the same as doing the task manually can not be efficient or even possible. Escape sequences can be defined as the special characters that can be used or provided to insert characters that are not viable to be typed by the user. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |