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:

For more Practice: Solve these Related Problems:
- Write a Python program to check if a string contains special characters.
- Write a Python program to replace all special characters in a string with a hyphen.
- Write a Python program to escape special characters in a string.
- Write a Python program to count the number of special characters in a given string.
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