0

Hey everyone,

Here's a question that should be pretty simple that I haven't found the answer to: if I'm using a function that takes some characters in quotes, what do I do if I want quotes to be some of those characters? I.e, if my code says

if c in '!,.?$%'

what would I do if I wanted to include an apostrophe along with !,.?$% for c?

3
Contributors
4
Replies
5
Views
9 Years
Discussion Span
Last Post by tortoiseman
0

Yes, what vegaseat suggested... either that or use an escape (a la \) before the text as in:

>>> t = '!,.?\'$%'
>>> print t
!,.?'$%
>>>

Same thing goes for double quotes within double-quoted string:

>>> t = "!,.?\"$%"
>>> print t
!,.?"$%
>>>
0

Using an escape character like jlm699 showed is the best general approach. You can even ecape the escape character like this ...
if c in "!,.?\'\"\\$%"

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.