String: Difference between revisions

From Computer Science Wiki
(Created page with "right|frame|Programming basics<ref>http://www.flaticon.com/</ref> In computer programming, a string is traditionally a sequence of characters, either as a...")
 
Line 5: Line 5:


== Example ==
== Example ==
Here we encounter some different syntax rules. Programming languages define strings differently. Please do pay attention to the quotation marks, double quotation marks, and triple quotation marks.


<syntaxhighlight lang="php">
<?php
$a = 1234.65; // decimal number
$a = -1234.54; // a negative number
?>
</syntaxhighlight>
In Python:
* Single quotes: 'allows embedded "double" quotes'
* Double quotes: "allows embedded 'single' quotes".
* Triple quoted: '''Three single quotes''', """Three double quotes"""
Triple quoted strings may span multiple lines - all associated whitespace will be included in the string literal.<ref>https://docs.python.org/3/library/stdtypes.html</ref>
<syntaxhighlight lang="python3">
myString = 'Hello World'
</syntaxhighlight>
In Javascript:
<syntaxhighlight lang="javascript">
// decimal number:
var a = 1234.65;
// a negative number:
var a = -1234.65;
</syntaxhighlight>


== Do you understand this? ==
== Do you understand this? ==

Revision as of 06:15, 7 August 2017

Programming basics[1]

In computer programming, a string is traditionally a sequence of characters, either as a literal constant or as some kind of variable.[2].


Example[edit]

Here we encounter some different syntax rules. Programming languages define strings differently. Please do pay attention to the quotation marks, double quotation marks, and triple quotation marks.

<?php
$a = 1234.65; // decimal number
$a = -1234.54; // a negative number
?>

In Python:

  • Single quotes: 'allows embedded "double" quotes'
  • Double quotes: "allows embedded 'single' quotes".
  • Triple quoted: Three single quotes, """Three double quotes"""

Triple quoted strings may span multiple lines - all associated whitespace will be included in the string literal.[3]

myString = 'Hello World'

In Javascript:

// decimal number:
var a = 1234.65; 
// a negative number:
var a = -1234.65;

Do you understand this?[edit]

Standards[edit]

  • Define the terms: variable, constant, operator, object.

References[edit]