Skip to content

Files

33 lines (28 loc) · 912 Bytes

File metadata and controls

33 lines (28 loc) · 912 Bytes

Python Strings

The simplest form of text sequences in Python is a str or strings.

To write a string in Python you have 4 options:

  1. Using single quotes: myStr = 'this allows "double" quotes inside'
  2. using double quotes: myStr = "this allows 'single' quotes inside"
  3. Using triple single quotes:
myStr = '''Three quotes allows
for multiline strings.
Cool right?'''
  1. Using triple double quotes:
myStr = """Three quotes allows
for multiline strings.
Isn't that even cooler?"""

Strings are considered 'immutable' meaning they can not be changed; however, two strings can be concatenated together using the + operator.

Example:

firstName = 'Jane'
lastName = 'Doe'
fullName = "My full name is: " + firstName + " " + lastName + "."

Instructions:
Mini-Mad-Lib:

  • Assign strings to each variable.
  • Then concatenate everything together in the mySentence variable