One Pager Cheat Sheet
- In this lesson, we will explore the
string
type and common related operations in introductory programming languages. - Strings are a data type in most programming languages which are declared by enclosing characters with
single ('')
ordouble quotation marks ("")
and contain asequence of characters
orarray of characters
which can be accessed and manipulated with properties and methods. - Python and JavaScript strings can be declared with single or double quotations, and their characters can be accessed with indices starting from 0, as illustrated by
name[2]
printingr
. - Yes, both Python and JavaScript support declaring a
string literal
using single or double-quotation marks, as evidenced by the code blocks above. - Strings in programming languages such as Python and JavaScript are collections of characters, including both upper and lower case letters,
numbers
,symbols
, and other characters, and are therefore not case-sensitive. - Strings can be manipulated through comparison, combination, removal, and addition of characters or
strings
in programming languages. Python
andJavaScript
support string concatenation, multiplication, and multiple built-in methods to manipulate strings.- The
+
operator in Python is used to concatenate strings, such as"Sara"
and"12"
stored in variablesname
andage
, respectively, resulting in the output string"Sara12"
. - The
print()
function in JavaScript prints the number of spaces in the argumenttext
, which in this example is 4. - Strings are
immutable
and cannot be reassigned characters, sodouble quotation marks
must be used when includingsingle quotation marks
in a string. - We
discussed
various string operations that can be used tomodify
and understand theproperties
of already declared string variables.