ef hlutstreng ekki í band python
fullstring = "StackAbuse"
substring = "tack"
if fullstring.find(substring) != -1:
print "Found!"
else:
print "Not found!"
python athuga hvort string í band
if "blah" not in somestring:
continue
hvernig á að athuga hvort það er orð í streng í python
>>> str = "Messi is the best soccer player"
>>> "soccer" in str
True
>>> "football" in str
False
hvernig á að stöðva fyrir hlutstreng í python
def find_string(string,sub_string):
return string.find(sub_string)
#.find() also accounts for multiple occurence of the substring in the given string
ef hlutstreng ekki í band python
>>> string = "Hello World"
>>> # Check Sub-String in String
>>> "World" in string
True
>>> # Check Sub-String not in String
>>> "World" not in string
False
python athuga hvort string
type('hello world') == str
# output: True
type(10) == str
# output: False