20050119: quoting strings

Discussion in 'Python' started by Xah Lee, Jan 10, 2005.

  1. Xah Lee

    Xah Lee Guest

    #strings are enclosed in double quotes quotes. e.g.
    a="this and that"
    print a

    #multiple lines must have an escape backslash at the end:
    b="this\n\
    and that"
    print b

    #One can use r"" for raw string.
    c=r"this\n\
    and that"
    print c

    #To avoid the backslash escape, one can use triple double quotes to
    print as it is:
    d="""this
    and
    that"""
    print d

    ---------------
    # in Perl, strings in double quotes acts as Python's triple """.
    # String is single quote is like Python's raw r"".
    # Alternatively, they can be done as qq() or q() respectively,
    #and the bracket can be just about any character,
    # matching or not. (so that escapes can be easy avoided)

    $a=q(here, everthing is literal, $what or \n or what not.);
    $b=qq[this is
    what ever including variables $a that will be
    evaluated, and "quotes" needn't be quoted.];
    print "$a\n$b";

    #to see more about perl strings, do on shell prompt
    #perldoc -tf qq
    Xah

    http://xahlee.org/PageTwo_dir/more.html
     
    Xah Lee, Jan 10, 2005
    #1
    1. Advertising

  2. Xah Lee

    Steve Holden Guest

    Xah Lee wrote:

    > #strings are enclosed in double quotes quotes. e.g.
    > a="this and that"
    > print a
    >
    > #multiple lines must have an escape backslash at the end:
    > b="this\n\
    > and that"
    > print b
    >
    > #One can use r"" for raw string.
    > c=r"this\n\
    > and that"
    > print c
    >
    > #To avoid the backslash escape, one can use triple double quotes to
    > print as it is:
    > d="""this
    > and
    > that"""
    > print d
    >
    > ---------------
    > # in Perl, strings in double quotes acts as Python's triple """.
    > # String is single quote is like Python's raw r"".
    > # Alternatively, they can be done as qq() or q() respectively,
    > #and the bracket can be just about any character,
    > # matching or not. (so that escapes can be easy avoided)
    >
    > $a=q(here, everthing is literal, $what or \n or what not.);
    > $b=qq[this is
    > what ever including variables $a that will be
    > evaluated, and "quotes" needn't be quoted.];
    > print "$a\n$b";
    >
    > #to see more about perl strings, do on shell prompt
    > #perldoc -tf qq
    > Xah
    >
    > http://xahlee.org/PageTwo_dir/more.html
    >


    Well, that gets that sorted out, then.

    Tomorrow: using single quotes. Using single quotes. The larch.

    regards
    Steve
    --
    Steve Holden http://www.holdenweb.com/
    Python Web Programming http://pydish.holdenweb.com/
    Holden Web LLC +1 703 861 4237 +1 800 494 3119
     
    Steve Holden, Jan 10, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Xah Lee
    Replies:
    0
    Views:
    258
    Xah Lee
    Jan 19, 2005
  2. Michal Duda

    quoting strings

    Michal Duda, Jan 31, 2006, in forum: Python
    Replies:
    1
    Views:
    339
    Fredrik Lundh
    Jan 31, 2006
  3. Ben

    Strings, Strings and Damned Strings

    Ben, Jun 22, 2006, in forum: C Programming
    Replies:
    14
    Views:
    787
    Malcolm
    Jun 24, 2006
  4. Xah Lee

    20050119: quoting strings

    Xah Lee, Jan 10, 2005, in forum: Perl Misc
    Replies:
    1
    Views:
    64
    Steve Holden
    Jan 10, 2005
  5. Xah Lee
    Replies:
    0
    Views:
    90
    Xah Lee
    Jan 19, 2005
Loading...

Share This Page