© 2019 BrainStemSchool.com

December 13, 2016

December 9, 2016

December 7, 2016

Please reload

Exploring String Delimiters

November 21, 2016

 

 https://youtu.be/vqUJYJqpzBI


Delimiters are the characters that start and stop a certain part of code.

 

Strings, or groups of characters, can be delimited in 4 ways in Python:

 

'Single Quotes' (apostrophe)

"Double Quotes" (quotation marks)

'''Triple Single Quotes''' (multi-line strings)

"""Triple Double Quotes""" (multi-line strings)

 

Each of these strings is the same in the memory of Python interpreter but:

 

Multi-line strings are easiest to code with the multi-line delimiters:

 

print("First line,

second line,

third line,

go.")

 

Will print:


First line,

second line

third line,

go.

 

It's not so important when TO use each, but more important when NOT to use each.

 

For instance, if you need an ' in your output, it's simple to use " for a delimiter:

 

print("It's mine.")

 

Or if you need " in your output, use ':

 

print('The cat said, "meow"')

 

But trouble ensues if you need both in your string such as printing the phrase:

 

He said, "It's your fault."

 

You could accomplish this with triple-single quotes:

 

print('''He said, "It's your fault."''')


or using Escape Characters (special sequences of characters to print single characters)

 

print("He said, \"It's your fault\"")


For instance notice the \" in code prints " in output.

 

Next Post: Who is "You" Revisited

Share on Facebook
Share on Twitter
Please reload

Please reload

Recent Posts
Tags