python - easy to understand (with comments)
\nclass Solution:\n    def convertToBase7(self, num: int) -> str:\n\t\t# Store each digit in array as we iterate\n        s = []\n\t\n\t\t# Base case where whil
```\nclass Solution:\n    def convertToBase7(self, num: int) -> str:\n\t\t# Store each digit in array as we iterate\n        s = []\n\t\n\t\t# Base case where while loop never runs\n        if num == 0:\n            return "0"\n\t\t\n\t\t# If num is negative, make it positive so the calculation is easier\n\t\t# Add a boolean flag\t\n\t\tf = False\n        if num < 0:\n            f = True\n            num = -num\n\t\t\n\t\t# While our division (into base 7) requires more steps to finish adding digits\n        while num > 0:\n\t\t\t# Append the next digit to the array\n\t\t\t# This begins from the smallest digit (rightmost)\n\t\t\t# Thus, we must reverse the string after we finish\n\t\t\t# (Last computation => Largest digit)\n\t\t\t\n            s.append(str(num%7))\n\t\t\t\n\t\t\t# Perform the actual division by our base, 7, on num\n            num //= 7\n\t\t\n\t\t# If it is negative add a \'-\', then join into a string and return\n\t\t# Again, s is reversed in order to place larger digits first\n        return (\'-\' if f else \'\') +\'\'.join(s[::-1])\n```
['Python', 'Python3']