3 ms·
Triple quoted string is just a way to write a string in multiple lines. There is no multi line comment in Python.
by iamd3vil 10y ago
Triple quoted string is just a way to write a string in multiple lines. There is no multi line comment in Python.
- thewhitetulip 10y agoYes, indeed. Triple quoted strings are just a way to write strings, but isn't that also a suitable way to write multiple line comments? The reason behind it is that otherwise you'll have to add `#` to every file and it becomes tedious! I have been using triple quoted strings as comments for a long time. But you are right, that's not the exact usecase for triple quoted strings, so I'll state that clearly. Thank you!
- guitarbill 10y agoPlease no. Most editors have a comment/uncomment function which you can use on multiple lines at once. Abusing triple quoted strings for commenting is bad practice. I'd avoid it out of principle, because it's semantically the same as proper strings and looks the same with code highlighting, so it increases cognitive load. But also because they might be interpreted as docstrings mistakenly, either by other programmers, or the documentation tool itself. A good rule, especially for beginners, is that triple quotes are primarily for docstrings, and the occasional multi line string. (Too many multi line strings, and it's probably a good idea to put them in a separate file) Edit: There's also other errors with this "anti-book", including basic stuff like operators. For example, the major operator list at the top is missing "or", the Boolean part probably needs a bit more info on truthiness as "not" works on non-Boolean types also, and the membership test operator ("in") works on many other data types, not just lists. And of course, "!=" == "xor".
- thewhitetulip 10y agoTrue, I am updating the multi line comment as doc strings and will include your comments, thank you! Also 'or' is not missing from my "anti-textbook", or is present, I am not sure why you think so. I am yet to reciew thr tutorial once so hopefully mistakes like the in operator would be rectified soon! Thanks :-)
- jamiesonbecker 10y agoIf you're using vim, press control-V and move your cursor up or down to create a vertical block. And if you're not, ya gotta get yourself some vim ;)
- thewhitetulip 10y agoI am yet to learn how to do vertical edits though, I use macros for that.