What is the difference between {} and [] in python?

There is no difference at runtime. The only difference between the two types of quotes is the one you have already pointed out:

  • Single quotes need to be escaped inside single quoted string literals but not inside double-quoted string literals.
  • Double quotes need to be escaped inside double quoted string literals but not inside single-quoted string literals.

Note: If you use triple-quoted strings ("""foo""" or '''bar''') then you dont need to escape either (unless you happen to have a sequence of three quotes in a row inside the string).

Tags:

Python

Syntax