+ 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âââ?
6 Antworten
+ 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 :)
+ 6
" " and ' ' indicate strings and """ """ indicates multiple line comment
+ 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
+ 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"""
+ 1
Thanks everyone! Really appreciate your help :p
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...â