Is there any way such that the words inside can be determined without using ,(comma) and separating them all with "(double quote | Sololearn: Learn to code for FREE!
+ 2

Is there any way such that the words inside can be determined without using ,(comma) and separating them all with "(double quote

words = ["spam", "egg", "spam", "sausage"] print("spam" in words) print("egg" in words) print("tomato" in words)

1st Oct 2018, 1:11 AM
partha
partha - avatar
4 Answers
+ 2
Not really. Python lists are defined using commas and brackets. But you can easily turn a space-separated string into a list: words = "spam egg spam sausage".split() print(words) #Output is ['spam', 'egg', 'spam' , 'sausage']
1st Oct 2018, 1:38 AM
Kishalaya Saha
Kishalaya Saha - avatar
+ 2
partha well... it's actually same as Kishalaya's, only changed space to double quotes if you mean the double quotes in single ones: in python, both single and double quotes can used to define a string object for example, 'with single quote' "with double quote" and when you used double quotes to define the string, you don't need a backlash("\") even if there's single quotes in the string, and vice versa for example, "It's a string" == 'It\'s a string' "This: \", is a double quote" == 'This: ", is a double quote'
1st Oct 2018, 1:45 PM
Flandre Scarlet
Flandre Scarlet - avatar
+ 1
you mean this? words = 'spam"egg"spam"sausage'.split('"') if the string used '(single quote), the double quotes inside will be treated as an character, and vice versa😀
1st Oct 2018, 7:09 AM
Flandre Scarlet
Flandre Scarlet - avatar
0
hey Flandre Scarlet sry I didn't get what you said can you give another example or Link to some code like that?
1st Oct 2018, 1:34 PM
partha
partha - avatar