You can simply use a here-document:
result=$(python <<EOF
import stuff
code = "${code}"
print("Hello from Python")
print("Code variable is:", code)
EOF
)
This way the Python code stays readable, and Bash variables like $code are expanded correctly