w3resource

Python: Define a string containing special characters in various forms

Python Basic: Exercise-92 with Solution

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:

Flowchart: Define a string containing special characters in various forms.

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.



Follow us on Facebook and Twitter for latest update.