String is nothing but an text. The plain text is called as string in programming. It can be done by adding two single or double quotation marks between the text.
>>>"Python is easy!"
'Python is easy'
In string, some characters are cannot be included directly. Because each character in Python has represent something. In order to print that characters as a string, we use escaping character (back slash) \.
for an example
>>>"Hello "How are you"?"
File "<stdin>", line 1
Hello "How are you"?"
^
SyntaxError: invalid syntax
To avoid this, add back slash before the character
>>>"Hello, \"How are you\"?"
'Hello, "How are you"?
>>>print("Hello \nPython!")
Hello
Python!
>>>"Python is easy!"
'Python is easy'
In string, some characters are cannot be included directly. Because each character in Python has represent something. In order to print that characters as a string, we use escaping character (back slash) \.
for an example
>>>"Hello "How are you"?"
File "<stdin>", line 1
Hello "How are you"?"
^
SyntaxError: invalid syntax
To avoid this, add back slash before the character
>>>"Hello, \"How are you\"?"
'Hello, "How are you"?
New Lines
Add \n to get a new line.>>>print("Hello \nPython!")
Hello
Python!
No comments:
Post a Comment