Strings

Strings

Strings are sequences of characters in Python

In short, Strings are/can be bits of text, numbers, and symbols that can be stored

The common way of denoting a string is to surround it with quotation marks, double or single

"This is a string"
'This is also a string'
"23" # this is a string even though it contains only a number

Strings must begin and end with the same type of quotation mark

# These are not valid strings since they start and begin with different quotation marks
"This is not a valid string'

'This is also not a valid string"

Additionally we can nest quotation marks within strings if they are of different count

"Your vs You're" # contains a single quote within double quotes string
'"I like python," said James' # contains double quotes within a single quote string

String Operator(s)

Like numbers, strings can be manipulated in many ways. The most basic string manipulation is called concatenation

Concatenation is the ability to ‘add’ one or more strings together using the + symbol

"Hello" + "Goodbye" # equals HelloGoodbye
'Sweet' + ' ' + 'and' + ' ' + 'sour' # equals Sweet and sour
"John " + "Doe" # equals John Doe

Later, we’ll explore some more of the different methods that the String Class has to offer in Python