ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-tutor
python-tutor
Re: [Tutor] OOPs Concept
by Matthew White other posts by this author
Apr 19 2006 8:49AM messages near this date
Re: [Tutor] OOPs Concept | Re: [Tutor] Tutor Digest, Vol 26, Issue 62
On Wed, Apr 19, 2006 at 09:10:41PM +0530, Kaushal Shriyan (kaushalshriyan@gmail.com) wrote:
>  Thanks Matthew
>  Just wanted to know
>  x.count('l') -> 2 Here 2 means what I didnot understood this
>  and also does x is a object and capitalize(), swapcase()  and
>  count('l') are methods, is that correct what i understand

yes, count(), capitalize(), and swapcase() are called methods.

The count() method counts the number of the given string in the object.

x = 'hello'
x.count('l')     ->  2
x.count('h')     ->  1

y = 'good morning'
y.count('o')     ->  3
y.count('oo')    ->  1

you can find out which methods belong to an object using the dir()
function and can get help for a method by using the help() function:

% python
Python 2.3.5 (#2, Sep  4 2005, 22:01:42) 
[GCC 3.3.5 (Debian 1:3.3.5-13)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
> >> x = 'hello'
> >> dir(x)
['__add__', '__class__', '__contains__', '__delattr__', '__doc__',
'__eq__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__',
'__getslice__', '__gt__', '__hash__', '__init__', '__le__', '__len__',
'__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__',
'__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__',
'__str__', 'capitalize', 'center', 'count', 'decode', 'encode',
'endswith', 'expandtabs', 'find', 'index', 'isalnum', 'isalpha',
'isdigit', 'islower', 'isspace', 'istitle', 'isupper', 'join', 'ljust',
'lower', 'lstrip', 'replace', 'rfind', 'rindex', 'rjust', 'rstrip',
'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title',
'translate', 'upper', 'zfill']
> >> help(x.swapcase)
Help on built-in function swapcase:

swapcase(...)
	S.swapcase() ->  string
	    
    Return a copy of the string S with uppercase characters
    converted to lowercase and vice versa.
> >>			


-mtw

-- 
Matthew White - District Systems Administrator
Tigard/Tualatin School District
503.431.4128

"The greatest thing in this world is not so much where we are, but in
what direction we are moving."   -Oliver Wendell Holmes

_______________________________________________
Tutor maillist  -  Tutor@[...].org
http://mail.python.org/mailman/listinfo/tutor
Thread:
Kaushal Shriyan
Matthew White
Kaushal Shriyan
Matthew White

Privacy Policy | Email Opt-out | Feedback | Syndication
© 2004 ActiveState, a division of Sophos All rights reserved