Docs missing info? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: General (https://python-forum.io/forum-1.html) +--- Forum: News and Discussions (https://python-forum.io/forum-31.html) +--- Thread: Docs missing info? (/thread-3747.html) |
Docs missing info? - tozqo - Jun-20-2017 I watched "Python Programming" by Derek Banas on YouTube, he mentions newlines, and I decide to play around with it a little print('hello', \n, 'world)being the simplest example. I run the code expecting but instead get a popup: I figure whatever, not really important, and fiddle around until I get it working the same as the video. But then, I try another neat trick to only check the first letter of a word, which is supposed to be \b , and I'm not figuring out how to get it to work. No matter where I put it, I get the syntax error.So I think, "Let's check the doc." Search for \b: no results. Search for \n: no results. Search for line continuation character: no results. Check index: no results. OK, let's try a different version. Change from 3.6 to 2: same thing. Alright, if first != success try = againSo I spend 20 minutes looking on the forums for anything helpful and, try = again. SO, does anyone know if I should be able to find this information in the docs? What is a line continuation character? Where should I look to find all the things I can use a backslash for? RE: Docs missing info? - buran - Jun-20-2017 you should pay more attention to details - you are missing number of quotes in the code print('hello', '\n', 'world') # here \n is an escape sequence for new lineyou can find more info here https://docs.python.org/3.6/reference/lexical_analysis.html?#literals and here is example from PEP8 for use of \ as line continuation char with open('/path/to/some/file/you/want/to/read') as file_1, \ open('/path/to/some/file/being/written', 'w') as file_2: file_2.write(file_1.read()) RE: Docs missing info? - tozqo - Jun-20-2017 Fixed my typo to have the correct number of quotes, and it worked. I remember putting \n and \b in quotes, and getting the error, but I have alot of times where I have missed things I thought I hadn't. Thanks for the reference to literals and the PEP. Gonna be reading for awhile. RE: Docs missing info? - Kebap - Jun-21-2017 you can also put the escape characters in your string directly. Print will know how to handle. print('hello\nworld') # again \n is an escape sequence for new line |