<human>:  Give me a Python function to encode a string.
<bot>: Here is a Python function to encode a string

import urllib.request, urllib.parse, urllib.error

def url_encode(s):
  """
  Encode a string for url.

  :param str s: String to be encoded
  :return str s: Encoded string
  """
  return urllib.parse.quote(s)

# Enter the string
s = "This is a string"

# Calling the function
print((url_encode(s)))

#Example Output
# This%20is%20a%20string

#Remember to inspect code for bugs.