| Forum Home | ||||
| PC World Chat | ||||
| Thread ID: 126779 | 2012-09-18 00:12:00 | Python question | Nick G (16709) | PC World Chat |
| Post ID | Timestamp | Content | User | ||
| 1301738 | 2012-09-18 00:12:00 | I'm trying to learn python, have a quick question. I have a some variables like one = hi two = how three = are four = you. Not really what I have, but you get the idea :) What I'd like to do would be to be able to get a end result like this hi how are you. So, I have tried two things. The first was print one \n two \n three \n four , but this gave me this 'unexpected character after line continuation character' Next I tried this example = one \n two \n three \n four , and then print example , but this didn't work either. How do I achieve what I want here? I'm using python 2.7.3 by the way. If needed, I can copy and paste my actual code. :thanks |
Nick G (16709) | ||
| 1301739 | 2012-09-18 02:58:00 | "PPPPPSSSSIIIIIIIIIIIYYYYYYYYAAAAAAAAAA HHHHAAASSSSAAAASSSSHHHHHHIIIIIII PPPPPSSSSIIIIIIIIYYYYYAAAAAA HHHHHAAAAASSSSSIIIIIIHHHHHEEEETHHHHHHHHH" - Harry Potter and the Chamber of Secrets Oh wait you mean like the programing language? =D See : bash.org |
lordnoddy (3645) | ||
| 1301740 | 2012-09-18 03:24:00 | :lol: That is funny :D | Nick G (16709) | ||
| 1301741 | 2012-09-18 04:23:00 | Hi, I am learning python too and I think what you want to do is something like this: >>> print one, '\n', two, '\n', three, '\n' the variables that you want to print must be separated by commas and since you are trying to print a string you need to wrap your \n in quotes. |
Fifthdawn (9467) | ||
| 1301742 | 2012-09-18 04:45:00 | print "%s\n%s\n%s\n%s" % (one, two, three, four) or print one, "\n", two, "\n", three, "\n", four |
Erayd (23) | ||
| 1301743 | 2012-09-18 05:08:00 | or print one, "\n", two, "\n", three, "\n", four Works great thanks! Guess my attempt needed a comma before and after the \n. Cheers EDIT - Thanks also Fifthdawn, will work as well :) |
Nick G (16709) | ||
| 1301744 | 2012-09-18 05:36:00 | I'm learning Basic at the moment. Not to hard really. Will try Python some other time. Nick, you've been asking a lot of questions lately. :) |
ChazTheGeek (16619) | ||
| 1301745 | 2012-09-18 07:52:00 | I'm learning Basic at the moment. Not to hard really. Will try Python some other time. Nick, you've been asking a lot of questions lately. :) I'm learning Visual Basic 2010 which is quite easy. Lol |
stratex5 (16685) | ||
| 1301746 | 2012-09-19 05:34:00 | Whats that like? Is it similar to Basic? | ChazTheGeek (16619) | ||
| 1301747 | 2012-09-19 05:40:00 | It is surprisingly enough. | icow (15313) | ||
| 1 2 3 | |||||