Posted on December 30, 2020
Some basic examples of creating strings in Python.
# create a string with single quotes or double quotes s1 = 'hello' s2 = "hello there" # use \ to escape a single quote or use double quotes s3 = 'that ain\'t the one' s4 = "that ain't the one" # triple quotes can also be used s5 = """another string"""
Methods available for the string type are demonstrated below.
>>> s = 'i love apples' # return a copy of the string where the first letter is capitalized >>> s.capitalize() 'I love apples' # return a copy of the string where words start with an uppercase >>> s.title() 'I Love Apples'
Gavin Wiggins © 2020