• Tuple is sequence, like a list of variables.
  • Tuple is immutable. It can’t be changed.

Example

def method()
  # doing
  return a, b

(a,b) is a tuple. It contains 2 variables
If you need to return more than 3 variables. You should create a class instead.

chat.py

Today we will use Tuple as a method return type.

def __get_default_reply(self, message=None):
    message_id = message['message_id']
    chat_id = message['chat']['id']
    msg = 'I understand only text and sticker messages'
    data = urllib.urlencode({
        'chat_id': str(chat_id),
        'text': msg.encode('utf-8'),
        'reply_to_message_id': str(message_id),
    })
    return 'sendMessage', data

def __get_text_reply(self, message=None):
    message_id = message['message_id']
    chat_id = message['chat']['id']
    first_name = message['from']['first_name']
    msg = 'Yo {} I got your message'.format(first_name)
    data = urllib.urlencode({
        'chat_id': str(chat_id),
        'text': msg.encode('utf-8'),
        'reply_to_message_id': str(message_id),
    })
    return 'sendMessage', data

def __get_sticker_reply(self, message=None):
    chat_id = message['chat']['id']
    file_id = message['sticker']['file_id']
    data = urllib.urlencode({
        'chat_id': str(chat_id),
        'sticker': file_id.encode('utf-8'),
    })
    return 'sendSticker', data

def __get_reply(self):
    message = self.__get_message()
    if message:
        if 'sticker' in message:
            return self.__get_sticker_reply(message)
        elif 'text' in message:
            return self.__get_text_reply(message)
        else:
            return self.__get_default_reply(message)
    return None, None

def send_reply(self):
    reply_method, data = self.__get_reply()
    if data:
        requestUrl = '{}/{}'.format(BASE_URL, reply_method)
        resp = urllib2.urlopen(requestUrl, data).read()
        logging.info('Reply is sent with response: {0}'.format(resp))
    else:
        logging.info('Send reply fail')
        resp = None