[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Home]
4Archive logo
I'm programming in Python and "\n"...
If images are not shown try to refresh the page. If you like this website, please disable any AdBlock software!

You are currently reading a thread in /g/ - Technology

Thread replies: 32
Thread images: 4
File: 1452979824962.jpg (94 KB, 720x479) Image search: [iqdb] [SauceNao] [Google]
1452979824962.jpg
94 KB, 720x479
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 (11 KB, 642x221) Image search: [iqdb] [SauceNao] [Google]
python2.png
11 KB, 642x221
>>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 (603 KB, 712x840) Image search: [iqdb] [SauceNao] [Google]
1451919077001.png
603 KB, 712x840
>>
>>52508086
Use double quote. Single quote is for string literals.
>>
File: 1430585168887.jpg (38 KB, 589x399) Image search: [iqdb] [SauceNao] [Google]
1430585168887.jpg
38 KB, 589x399
>>
>>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 replies: 32
Thread images: 4
Thread DB ID: 447180



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

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

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 shown content originated from that site. This means that 4Archive shows their content, archived. If you need information for a Poster - contact them.
If a post contains personal/copyrighted/illegal content, then use the post's [Report] link! If a post is not removed within 24h contact me at wtabusse@gmail.com with the post's information.