Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > 20050119: quoting strings

Reply
Thread Tools

20050119: quoting strings

 
 
Xah Lee
Guest
Posts: n/a
 
      01-10-2005
#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://www.velocityreviews.com/forums/(E-Mail Removed)
http://xahlee.org/PageTwo_dir/more.html

 
Reply With Quote
 
 
 
 
Steve Holden
Guest
Posts: n/a
 
      01-10-2005
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
> (E-Mail Removed)
> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Strings, Strings and Damned Strings Ben C Programming 14 06-24-2006 05:09 AM
What are all these nonesence sites quoting mine but with no content? xyZed HTML 8 04-05-2006 04:52 PM
quoting strings Michal Duda Python 1 01-31-2006 01:49 PM
20050119: quoting strings Xah Lee Perl Misc 1 01-10-2005 10:35 AM
Quoting original messages in replies John Coxon Firefox 14 04-24-2004 06:18 PM



Advertisments