Python: Define a string containing special characters in various forms
Special Characters in String
Write a Python program to define a string containing special characters in various forms.
Sample Solution:
Python Code:
# Print a string containing special characters without escaping.
print()
print("\#{'}${\"}@/")
# Print a string containing special characters with escaped single quotes.
print("\#{'}${\"}@/")
# Print a raw string using triple-quotes with special characters.
print(r"""\#{'}${"}@/""")
# Print a string containing special characters without escaping.
print('\#{\'}${"}@/')
# Print a string containing special characters with escaped single quotes.
print('\#{'"'"'}${"}@/')
# Print a raw string using triple-quotes with special characters.
print(r'''\#{'}${"}@/''')
print()
Sample Output:
\#{'}${"}@/ \#{'}${"}@/ \#{'}${"}@/ \#{'}${"}@/ \#{'}${"}@/ \#{'}${"}@/
Flowchart:
Python Code Editor:
Previous: Write a Python program to swap two variables.
Next: Write a Python program to get the identity of an object.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics