# D-string vs str.dedent()

**URL:** <https://discuss.python.org/t/d-string-vs-str-dedent/35907>\
**Category:** Ideas\
**Created:** [October 11, 2023, 7:43am UTC](https://discuss.python.org/t/d-string-vs-str-dedent/35907 "2023-10-11T07:43:28Z")\
**Posts on this page:** 1\
**Showing post:** 18

<div class="post-metadata">

**Author:** ![storchaka](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/storchaka/32/217_2.png) [@storchaka](https://discuss.python.org/u/storchaka)\
**Post date:** [October 12, 2023, 1:11pm UTC](https://discuss.python.org/t/d-string-vs-str-dedent/35907/18 "2023-10-12T13:11:15Z")

</div>

With d-strings you can write the following:

```auto
def f():
    return d"""First shalt thou take out the Holy Pin.
        Then shalt thou count to three, no more, no less.
        Three shall be the number thou shalt count, and the number of the \
        counting shall be three.
        Four shalt thou not count, neither count thou two, excepting that \
        thou then proceed to three.
        Five is right out!
        Once the number three, being the third number, be reached, then \
        lobbest thou thy Holy Hand Grenade of Antioch towards thy foe, \
        who, being naughty in My sight, shall snuff it."""

```

Sentences are separated by newlines, long sentences are split on several physical lines on 80 columns in the source code, and these lines are nuicely indented, but the resulting string do not contain newlines or extra spaces in the middle of sentence. It is not possible to do this with `str.dedent()`.

---

_[View the full topic](https://discuss.python.org/t/d-string-vs-str-dedent/35907)._
