What is the syntax for strings?

  • use single or double quotation marks to denote a string value
  • use * operator to multiply strings
  • use + to concatenate strings
  • use \n to print the rest of the string on a new line
  • place an r in front of your opening quotation mark to tell computer to ignore all special meanings of \
#examples
>>> "Hello World"
'Hello World'

>>> 'Hello World'
'Hello World'

>>> 'The person said "Hello World"'
'The person said "Hello World"'

>>> print("separate\nline")
separate
line

>>> "word"*4
'wordwordwordword'

>>> firstStr = 'Tom'
>>> secondStr = 'Jerry'
>>> firstStr + " and " + secondStr
'Tom and Jerry'
Advertisements