This question already has answers here:
How to list all functions in a module?
(20 answers)
Closed 4 years ago.
I am new to python. This question might duplicate.
How to know the methods of lists. After search in google, its come to know there are more than 10 methods like append,insert , ,. is there any command/syntax to know the available methods.
lists is for example.
print(dir(list)) will give you the available methods on a class.
or help(list) in the REPL for nicer formatting, as suggested by #DeepSpace
Related
This question already has answers here:
Why does Python code use len() function instead of a length method?
(7 answers)
In Python, when should I use a function instead of a method?
(5 answers)
Closed 5 months ago.
I expect this question risks being closed as opinion-based, but it is a genuine question, and I assume there is a technical answer.
The builtin functions len and type confuse me, because I keep wanting to write
x.len()
or even
x.len
instead of
len(x)
This is probably because I use numpy x.shape frequently, and
I wondered what the rationale for this is? I assume it is something related to being dynamically typed, or maybe something related to None, but I couldn't figure it out. Are there certain situations where having these as members (properties or methods) doesn't make sense? Or maybe it is a speed consideration?
This question already has answers here:
What does "three dots" in Python mean when indexing what looks like a number?
(3 answers)
What does the Ellipsis object do?
(14 answers)
Closed 2 years ago.
So I have created a suffix tree using python and when I was printing my suffix tree, I came across one list that contains [...] at one of its indexes. I searched online and couldn't find anything regarding it. It would be really great if someone could explain to me that what does [...] mean in python. By the way, I'm using PyCharm IDE, not sure if it's an IDE specific issue. Cheers!
This question already has answers here:
Why did Python 2.6 add a global next() function?
(3 answers)
Closed 6 years ago.
I'm new to python ,and just trying to figure out why two ways? any specific reason? which one is better?
I've tried searching but not able to find it.
The simplest answer is that the justification is similar for next(x) as it is for len(x). Fredrik Lund summarises Guido's response on that topic in this article.
This question already has answers here:
Finding what methods a Python object has
(22 answers)
Closed 8 years ago.
I'm a Ruby person migrating to Python. One thing that I miss is an easy way to see a list of all the methods that I could use on a particular object in a shell.
Is there an analogue to Ruby's Object#methods in Python?
Try dir(obj). It gives you a list of methods associated with obj.
This question already has answers here:
Why avoid while loops?
(13 answers)
Closed 9 years ago.
One of my teachers warned me not to use while in python. It is really strange for me as I have not found any articles on why to do so. What do you think on what could the grounds be?
Use the control statement that best suits your needs in each situation.
An advice like "Don't use while, only use for" boils down to "If the only tool you know is a hammer, all problems look like a nail."