Hi All,

I am using the .search function.

strValue="XXX"
strTemp1="YYYXXX"
strTemp= strTemp1.search(strValue)

Python is not able to recognise the .search function.
AttributeError: 'str' object has no attribute 'search'

What should I import for this?
Please help!

Recommended Answers

If you want to just find out if one string is contained inside another:

strvalue1 in strvalue2

If you want to find out how many occurrences of one string there are in another:

num = strvalue.count(strvalue2)

If you want to find the index of …

Jump to Post

All 2 Replies

Python is not able to recognise the .search function.
AttributeError: 'str' object has no attribute 'search'

yes...that would be the response
to find the available methods for string class..try help(string) at the python prompt...
that shud help

Peace...

If you want to just find out if one string is contained inside another:

strvalue1 in strvalue2

If you want to find out how many occurrences of one string there are in another:

num = strvalue.count(strvalue2)

If you want to find the index of the first occurrence of one string in another:

ind = strvalue1.find(strvalue2)
commented: nice help +12
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.