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?

Try ...
if c in "!,.?'$%"

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
!,.?"$%
>>>

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

Cool, thanks, people.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.