[Tutor] unable to use find(), index()

Christian Witts cwitts at compuscan.co.za
Thu Dec 8 12:37:20 CET 2011


On 2011/12/08 01:19 PM, surya k wrote:
> I am using the following code 
> astr = "foobar"str1 ="foo"astr.find(str1, beg=0, end=3)
>
> This is showing the following error
> Traceback (most recent call last):  File "<interactive input>", line 1, in<module>TypeError: find() takes no keyword arguments
> I even tried by importing "string" module, but it isn't working.
> This same problem with find()
> Could you please help me!
>
>   		 	   		
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
Your traceback message gives you the reason it's not working, `find() 
takes no keyword arguments`. The function only takes positional 
arguments so if you just write `astr.find(str1, 0, 3)` it will work as 
you expect it to.

 >>> help(''.find)
Help on built-in function find:

find(...)
     S.find(sub [,start [,end]]) -> int

     Return the lowest index in S where substring sub is found,
     such that sub is contained within s[start:end].  Optional
     arguments start and end are interpreted as in slice notation.

     Return -1 on failure.

-- 

Christian Witts
Python Developer
//
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111208/61f96e0a/attachment.html>


More information about the Tutor mailing list