Page 1 of 2 12 LastLast
Results 1 to 10 of 21

Thread: Python question

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Senior Member
    Join Date
    Mar 2012
    Posts
    3,301

    Default Python question

    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.


  2. #2
    Slipping into Madness lordnoddy's Avatar
    Join Date
    Jan 2009
    Location
    I've moved to the shore 0.o
    Posts
    1,170

    Default Re: Python question

    "PPPPPSSSSIIIIIIIIIIIYYYYYYYYAAAAAAAAAA HHHHAAASSSSAAAASSSSHHHHHHIIIIIII
    PPPPPSSSSIIIIIIIIYYYYYAAAAAA HHHHHAAAAASSSSSIIIIIIHHHHHEEEETHHHHHHHHH" - Harry Potter and the Chamber of Secrets
    Oh wait you mean like the programing language? =D

    See : http://bash.org/?400459
    Don't judge someone until you've walked a mile in their shoes... that way when you do judge them you're a mile away... and you have THEIR shoes!

  3. #3
    Senior Member
    Join Date
    Mar 2012
    Posts
    3,301

    Default Re: Python question

    That is funny

  4. #4
    Senior Member
    Join Date
    Jan 2009
    Posts
    170

    Default Re: Python question

    Hi, I am learning python too and I think what you want to do is something like this:
    Code:
    >>> 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.

  5. #5
    Gone Erayd's Avatar
    Join Date
    Dec 2004
    Location
    Wellington, NZ
    Posts
    5,761

    Default Re: Python question

    Code:
    print "%s\n%s\n%s\n%s" % (one, two, three, four)
    or
    Code:
    print one, "\n", two, "\n", three, "\n", four
    If you are interested in reading fanfiction on a mobile device or ebook reader, please visit flagfic.com.

  6. #6
    Senior Member
    Join Date
    Mar 2012
    Posts
    3,301

    Default Re: Python question

    Quote Originally Posted by Erayd View Post
    or
    Code:
    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
    Last edited by Nick G; 18-09-2012 at 04:10 PM.

  7. #7
    Senior Member
    Join Date
    Aug 2009
    Posts
    1,725

    Default Re: Python question

    Nick are you studying or just teaching yourself? I did an intro course to python last semester, it's quite easy once you get into it!

  8. #8
    Senior Member
    Join Date
    Mar 2012
    Posts
    3,301

    Default Re: Python question

    Quote Originally Posted by darkstar09 View Post
    Nick are you studying or just teaching yourself? I did an intro course to python last semester, it's quite easy once you get into it!
    I am doing a very basic course, but its not being run great, so I am trying to teach myself; as such not finding it very easy

  9. #9
    Senior Member
    Join Date
    Aug 2009
    Posts
    1,725

    Default Re: Python question

    Quote Originally Posted by Nick G View Post
    I am doing a very basic course, but its not being run great, so I am trying to teach myself; as such not finding it very easy
    Where at? I'm at the uni and can probably give you a hand if you like, PM me.

  10. #10
    Not in dev/null yet ChazTheGeek's Avatar
    Join Date
    Nov 2011
    Location
    Christchurch
    Posts
    1,365

    Default Re: Python question

    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.
    ASUS P8P67-M Pro | i5 2500k 4.2GHz | Hyper 212 EVO | GTX 970OC | 500B SSD | 2x 1TB WD Caviar Blue | | 16GB RAM | Corsair 400R | RM850

Similar Threads

  1. Quick Question on Python
    By xyz823 in forum PressF1
    Replies: 8
    Last Post: 14-03-2012, 11:35 AM
  2. python functions
    By johnd in forum PressF1
    Replies: 5
    Last Post: 15-08-2011, 08:17 PM
  3. Python Script
    By Faded_Mantis in forum PressF1
    Replies: 1
    Last Post: 18-02-2008, 07:14 AM
  4. Replies: 11
    Last Post: 09-06-2004, 11:44 AM
  5. Python
    By jonzsie in forum PressF1
    Replies: 4
    Last Post: 21-02-2003, 10:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •