[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

I'm programming in Python and "\n" doesn't

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 32
Thread images: 4

File: 1452979824962.jpg (94KB, 720x479px) Image search: [Google]
1452979824962.jpg
94KB, 720x479px
I'm programming in Python and "\n" doesn't work, what do?
>>
What do you mean? Which python? Try it as a char i guess

print ('\n')
>>
>>52507921
>Programming in Python
>Having issues
You get the fuck off here and get on google.
>>
What do you mean it doesn't work??
>>
>>52508012
It just prints "\n" as a string, also it's version 2.7.11.
>>
>>52507964
>not programming solely in BASIC

he should just kill himself already
>>
>>52508045
You're supposed to use the ' charachter to surround \n, not ".
>Having the fucking issue when you can't tell the difference between a charachter and a string.
>>
>>52508073
I'm already using single apostrophes
>>
>>52508069
I have bad news for you...
>>
File: python2.png (11KB, 642x221px) Image search: [Google]
python2.png
11KB, 642x221px
>>52508045
>>
OP here, I should have mentioned I use a mac

I know i'm retarded but somehow niggers don't steal it (this is laptop nr 5)
>>
Using a mac has nothing to do with this. Install a newer version of python like a logical fucking being, especially since it looks like you don't have to deal with version compatibility considering you can't even understand the new line character.

In python 3, you would type print("\n") to form a new line. This works. the backslash \ indicates an escape sequence where a special character follows (in this case the new line character 'n').

In python 2, I believe you would have to type print "hello world\n" with no parentheses.

You don't need single apostrophes or any of that shit. Just make sure to stay consistent. You can type print('hello world') and it will work. Python automatically interprets all variables as strings. If you use a single apostrophe before, don't use quotes later.

Also upload your full code next time.
>>
File: 1451919077001.png (603KB, 712x840px) Image search: [Google]
1451919077001.png
603KB, 712x840px
>>
>>52508086
Use double quote. Single quote is for string literals.
>>
File: 1430585168887.jpg (38KB, 589x399px) Image search: [Google]
1430585168887.jpg
38KB, 589x399px
>>
>>52509599
Wait wait what ? I was under the impression that a single and double quotes were both exactly the same in python
>>
Why do you even need to print a newline?
>>
>>52509643
They are. He's full of shit.
The only real reason to use one over the other is if you want a string with quotes in it and you don't want to use an escape or raw literal.
That, and preference.
>>
Wouldn't he have to escape the escape character to get just /n
>>
>>52510025
OP didn't even state what his problem was
>>
>>52509542
>>52508108

Almost:
1- Both python 2 and 3 support print("shit")
2- It does matter, because osx uses different line endix, so if you move a textfile to your mac you may run unto compatibility shit.

This though, should be in /sqt/ and have code so I'm not going to explain how you can fix it
>>
>>52509862
Good, I figured. Single quotes or die
>>
>>52507945
>as a char
you do realise ' and " characters both start a string, not a character, right? probably a Python 3 thing you're doing though
>>
try \r\n
>>
>>52507921
Python doesn't have a char data type. It's just a string of size 1
>>
>>52507921
You should always use os.linesep instead of /n. Unix line endings are /n and Windows is /r/n
>>
>>52511287
The difference is that ' makes a char and " makes a string, Python treats both of them the same way because it is dynamically typed but they are different
>>
>>52512063
just because it's that way in C doesn't mean it's the same everywhere else
>>>type('a')
<class 'str'> #or <type 'str'> on 2.7
>>
>>52512163
C has static typing, it has to tell the difference
>>
>>52512245
doesn't change the fact that ' in python makes strings
>>
>>52511564
As if windows users read output in terminal ever
>>
>>52508069
>Not flipping bits manually
Thread posts: 32
Thread images: 4


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.