Можете ли вы сделать перенос слов на ноутбуке i python в Google Colab? - PullRequest
0 голосов
/ 28 января 2020

Я бы хотел обернуть слово кодом python и выводить его в блокноте python внутри Google colab. Есть способ сделать это ? Установка вертикального выравнивания в настройках ноутбука не решила эту проблему для меня.

1 Ответ

0 голосов
/ 18 апреля 2020

Вы можете сделать что-то подобное в Google Colab с python встроенной библиотекой 'textwrap'

import textwrap

wrapper = textwrap.TextWrapper(width=40,
    initial_indent=" " * 4,
    subsequent_indent=" " * 4,
    break_long_words=False,
    break_on_hyphens=False)

string = "PURPOSE: To end world hunger, create peace for all people, solve all technological and scientific problems, make an exorbitant amount of money, and remain humble in the process."
print wrapper.fill(string)

output

    PURPOSE: To end world hunger, create peace for all people, solve all
    technological and scientific problems, make an exorbitant amount of money,
    and remain humble in the process.
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...