{"id":319,"date":"2013-09-19T04:18:22","date_gmt":"2013-09-19T04:18:22","guid":{"rendered":"http:\/\/www.pythonforspss.org\/?p=319"},"modified":"2015-01-27T08:05:41","modified_gmt":"2015-01-27T08:05:41","slug":"escape-sequence","status":"publish","type":"post","link":"https:\/\/www.spss-tutorials.com\/escape-sequence\/","title":{"rendered":"Escape Sequence (General Concept)"},"content":{"rendered":"<!--body-->\n<h2>Introduction<\/h2>\n\n<p>An escape sequence is a combination of characters that has a special meaning.<\/p>\n\n\n\t<h2>Escape Sequences in General<\/h2>\n\t\n<ul>\n\t<li>Some characters imply a <strong>special function<\/strong> rather than their \"normal\" meaning. For example, <code>'<\/code> often implies the start or the end of a <a href=\"https:\/\/www.spss-tutorials.com\/spss-string-variables-basics\/ \">string<\/a>.<\/li>\n\t<li>But what if you actually mean <code>'<\/code> rather than a string? In that case you can <strong>escape its default meaning<\/strong> by prefixing it, often with a backslash (as in <code>\\'<\/code>).<\/li>\n\t<li>Reversely, <code>\\n<\/code> usually implies a new line indicator. In this case, the backslash <strong>escapes the default meaning<\/strong> of <code>n<\/code> (which is simply <code>n<\/code>).<\/li>\n\t<li>Escape sequences thus work in <strong>two ways<\/strong>: they may <strong>apply<\/strong> a special function to a character that doesn't have one by default as in the case of (<code>\\n<\/code>) or they may <strong>disable<\/strong> a special function from a character that has one by default (<code>\\'<\/code>).<\/li>\n<\/ul>\n\t\n<h2>Escape Sequences in SPSS<\/h2>\n\n<ul>\n\t<li>In SPSS, quotes can be escaped by doubling them. This may be necessary when value labels or <a href=\"https:\/\/www.spss-tutorials.com\/spss-set-variable-labels-with-syntax\/#varlabs\">variable labels<\/a> contain quotes as in <code>ADD VALUE LABELS v1 1 'Don''t know'.<\/code>.<\/li>\n\t<li>If the second quote hadn't been doubled, it would have indicated the end of the value label immediately after \"Don\".<\/li>\n\t<li>An alternative here is to use double quotes <em>around<\/em> the value label and single quotes <em>within<\/em> it as in <code>ADD VALUE LABELS v1 1 \"Don't know\".<\/code>.<\/li>\n<\/ul>\n\n<h2 id='pythonbackslash'>Escaping in Python<\/h2>\n\t\n<ul>\n\t<li>In Python, escape sequences are indicated by a backslash (<code>\\<\/code>).<\/li>\n\t<li>The most important one may be <code>\\n<\/code> which indicates a new line. Like so, multiple logical lines can be stacked into a single physical line.<\/li>\n\t<li>Another escape sequence worth mentioning is <code>\\'<\/code> for a single quote within a <a href=\"https:\/\/www.spss-tutorials.com\/spss-string-variables-basics\/ \">string<\/a>.<\/li>\n\t<li>A backslash also escapes itself so if it's really a backslash you want, double it as in <code>\\\\<\/code>.<\/li>\n\t<li>For a demonstration of these point, run the <a href=\"https:\/\/www.spss-tutorials.com\/spss-syntax\/ \">syntax<\/a> below.<\/li>\n<\/ul>\n\t\n<h2>Python Escape Sequence Examples<\/h2>\n\t\n\t\n<div class='code'>begin program.<br>print &#39;line 1\\nline 2\\nline 3&#39;<br>print &#39;This is a backslash: \\\\&#39;<br>print &#39;Don\\&#39;t worry be happy!&#39;<br>end program.<\/div><!--class='code'-->\t\n\t\n\t\n\t\n\t\n","protected":false},"excerpt":{"rendered":"\n<p>An escape sequence is a combination of characters that has a special meaning.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-319","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/www.spss-tutorials.com\/wp-json\/wp\/v2\/posts\/319","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.spss-tutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.spss-tutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.spss-tutorials.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.spss-tutorials.com\/wp-json\/wp\/v2\/comments?post=319"}],"version-history":[{"count":0,"href":"https:\/\/www.spss-tutorials.com\/wp-json\/wp\/v2\/posts\/319\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.spss-tutorials.com\/wp-json\/wp\/v2\/media?parent=319"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.spss-tutorials.com\/wp-json\/wp\/v2\/categories?post=319"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.spss-tutorials.com\/wp-json\/wp\/v2\/tags?post=319"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}