Page 1 of 3 123 LastLast
Results 1 to 10 of 21

Thread: Python question

  1. #1
    Senior Member
    Join Date
    Mar 2012
    Posts
    3,296

    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,296

    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,296

    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 05:10 PM.

  7. #7
    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

  8. #8
    The Sane of Insanity stratex5's Avatar
    Join Date
    Jan 2012
    Location
    On Earth... I Think???
    Posts
    1,050

    Default Re: Python question

    Quote Originally Posted by ChazTheGeek View Post
    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
    Quote Originally Posted by Slankydudl View Post
    Dont buy computer components that are listed as faulty because when you get them they tend to not work very well.
    Quote Originally Posted by Metla View Post
    I've got a nice little system you can have.

    I just have to let my wife know that she can't have it anymore.

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

    Default Re: Python question

    Whats that like? Is it similar to Basic?
    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

  10. #10
    Pretends to know things
    Join Date
    Feb 2010
    Posts
    3,532

    Default Re: Python question

    It is surprisingly enough.

Similar Threads

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