+ 1

What’s the difference between quotes?

I’m really confused with using quotation marks to indicate strings in python. Can anyone please explain the difference between ‘ ‘, “ “, and “”” “””? Is it like ‘word’, “sentence.”, “””paragraphs”””?

11th Nov 2018, 3:50 AM
Lauren
6 Answers
+ 8
You can use either ' or " to start and end any string, as long as they match. You may want to use one to enclose the other, e.g. "that's" gives that's and 'he said "hi"' gives he said "hi" Otherwise you would have to use a backslash, e.g. to get that's just using single quotes, you would use 'that\'s' Here is a bit from the official blurb: https://legacy.python.org/dev/peps/pep-0008/#id25 Triple quotes (single or double, although single are discouraged) enclose multi-line comments and preserve the formatting, however these should generally only be used for docstrings, i.e. the first text in a module, function or class. - see https://legacy.python.org/dev/peps/pep-0257/#id15 Other multi-line comments should have # begin each line - see https://legacy.python.org/dev/peps/pep-0008/#id30 Oops SL says I'm out of characters - to be continued on next comment :)
11th Nov 2018, 5:04 AM
David Ashton
David Ashton - avatar
+ 6
" " and ' ' indicate strings and """ """ indicates multiple line comment
11th Nov 2018, 4:10 AM
Googel
Googel - avatar
+ 6
...continued To see how docstrings work, you can experiment in the Code Playground with stuff like this: def myfunc(a, b): """Return the product of 2 numbers.""" return a * b Then print(myfunc.__doc__) prints Return the product of 2 numbers. and help(myfunc) prints myfunc(a, b) Return the product of 2 numbers. Sorry if a got a bit carried away answering your question XD
11th Nov 2018, 5:16 AM
David Ashton
David Ashton - avatar
+ 4
" " and ' ' is use for to define string. e.g print("hi") #output=hi print('hi') #output=hi You can also use single and double quotes in your string according to your need. e.g if you want to also " " in your output then you can try this. print('"hi"') #output="hi" here you can also use / for not read to single or double quotes. e.g print("\"hi\"") #output=hi Here \ is escape sequence.to avoid the commas after it. And """ """" is use to define multiple comments in python. e.g """Hskjd Nzjxx Xnnxmx Sjkx"""
11th Nov 2018, 4:38 AM
Maninder $ingh
Maninder $ingh - avatar
+ 1
Thanks everyone! Really appreciate your help :p
11th Nov 2018, 3:33 PM
Lauren
0
Introduction to Regular Expressions Here’s the scenario: you’re given the job of checking the pages on a web server for doubled words (such as “this this”), a common problem with documents subject to heavy editing. Your job is to create a solution that will: Accept any number of files to check, report each line of each file that has doubled words, highlight (using standard ANSI escape sequences) each doubled word, and ensure that the source filename appears with each line in the report. Work across lines, even finding situations where a word at the end of one line is repeated at the beginning of the next. Find doubled words despite capitalization differences, such as with ‘The the...’, as well as allow differing amounts of whitespace(spaces, tabs, new-lines, and the like) to lie between the words. Find doubled words even when separated by HTML tags. HTML tags are for marking up text on World Wide Web pages, for example, to make a word bold: ‘...it is <B>very</B> very important...’
14th Nov 2018, 5:11 AM
IRONMAN