How do I write a string literal that includes quotation marks?
Question:
I want to create a string with this exact text: nuke.execute("Write1", 1, 10, 1)
Simply surrounding it with double quotes, like "nuke.execute("Write1", 1, 10, 1)"
, doesn’t work:
>>> "nuke.execute("Write1", 1, 10, 1)"
File "<stdin>", line 1
"nuke.execute("Write1", 1, 10, 1)"
^
SyntaxError: invalid syntax
>>>
How can I write the string literal in my code?
Answers:
Simply enclose it in single quotes:
'nuke.execute("Write1", 1, 10, 1)'
There are several alternatives, such as escaping the embedded quotes with backslashes:
"nuke.execute("Write1", 1, 10, 1)"
or using triple-quoted strings:
"""nuke.execute("Write1", 1, 10, 1)"""
or
'''nuke.execute("Write1", 1, 10, 1)'''
You can read more about Python string literals in the manual.
You can use single quotes:
'nuke.execute("Write1", 1, 10, 1)'
or you can use backslashes to “escape” the embedded quotes:
"nuke.execute("Write1", 1, 10, 1)"
You can escape the quotation marks using :
"nuke.execute("Write1", 1, 10, 1)'"
What’s wrong with 'nuke.execute("Write1", 1, 10, 1)'
?
I want to create a string with this exact text: nuke.execute("Write1", 1, 10, 1)
Simply surrounding it with double quotes, like "nuke.execute("Write1", 1, 10, 1)"
, doesn’t work:
>>> "nuke.execute("Write1", 1, 10, 1)"
File "<stdin>", line 1
"nuke.execute("Write1", 1, 10, 1)"
^
SyntaxError: invalid syntax
>>>
How can I write the string literal in my code?
Simply enclose it in single quotes:
'nuke.execute("Write1", 1, 10, 1)'
There are several alternatives, such as escaping the embedded quotes with backslashes:
"nuke.execute("Write1", 1, 10, 1)"
or using triple-quoted strings:
"""nuke.execute("Write1", 1, 10, 1)"""
or
'''nuke.execute("Write1", 1, 10, 1)'''
You can read more about Python string literals in the manual.
You can use single quotes:
'nuke.execute("Write1", 1, 10, 1)'
or you can use backslashes to “escape” the embedded quotes:
"nuke.execute("Write1", 1, 10, 1)"
You can escape the quotation marks using :
"nuke.execute("Write1", 1, 10, 1)'"
What’s wrong with 'nuke.execute("Write1", 1, 10, 1)'
?