195k views
2 votes
Write at least and explain four types of escape sequences and create an example in an IDE which consist of the mentioned escape sequences.

1 Answer

5 votes

Answer:

- \' is used to escape a single quote in a string enclosed in single quotes like;

my_string = 'this is John\'s ball'.

- \\ is used to jump to a new line, Eg;

my_string = "Johns is a good boy\\but he hates going to school."

the next set of the string after the '\\' character is displayed on the next line.

- \t is used to add a tab space to a string.

my_string = 'Jane is \thungry'

the character adds four character spaces before the word 'hungry'.

- \r adds a carriage return (or enter in keyboards) to start a new block paragraph in a string.

my_string = "Johns is a good boy\rbut he hates going to school."

Step-by-step explanation:

Escape sequences in programming are used to format strings or output syntax of a program. They always begin with the backslash. Examples of escape sequence are " \' ", "\\", "\t", "\r", etc.

User Skaz
by
4.6k points