简体   繁体   中英

Python - Quotation Marks as Variables

Is it possible to use quotation marks as a variable?

a = input("Insert Here")
If a is " " ":
       Do something

Also, would I have to do = or Is ?

If you have double quotes inside a string literal then use single quotes, or escape it.

Don't use is unless you want to see if two references refer to the same object. To test equality use == , a single = is an assignment:

a = input("Insert Here: ")
if a == '"':
   Do something

you have two options:

  1. Wrapping with single quotes: '"'
  2. Escaping with backslash: "\\""

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM