django/python variables inside strings?
Question: I'm new to python and would like some assistance.

I have a variable

    
    
    q = request.GET['q']
    

How do I insert the variable `q` inside this:

    
    
    url = "http://search.com/search?term="+q+"&location=sf"
    

Now I'm not sure what the convention is? I'm used to PHP or javascript, but
I'm learning python and how do you insert a variable dynamically?


Answer: Use the format method of String:

    
    
    url = "http://search.com/search?term={0}&location=sf".format(q)
    

But of course you should URL-encode the q:

    
    
    import urllib
    ...
    qencoded = urllib.quote_plus(q)
    url = 
      "http://search.com/search?term={0}&location=sf".format(qencoded)
    

