Firstly, I think part of your confusion is what exactly "variable" means. In Python it's not the best terminology because Python really has names (or identifiers), and values (or objects). Names point to values. For more on that, see Facts and myths about Python names and values by Ned Batchelder. Show Secondly, another part of your
confusion might be the difference between mutable and immutable types. Strings are immutable, but lists are mutable. Therefore strings can't have methods that mutate them, but lists can. (And for that matter, other functions can mutate them, e.g. Now, even with that out of the way, there's still some ambiguity, but the function documentation will almost always tell you. And if it helps, the difference here is between procedures, which are used for their side-effects*, and functions proper, which are used to return a value. See What is the difference between a "function" and a "procedure"? But these are just concepts; the reality
is a grey area; for example the file method Related concepts:
* Sidenote: "Mutator method" would seem like a natural fit, but that has a more specific definition in the context of OOP. Two lists, list1 and list2, contain the names of books found in two different collections. A librarian wants to create newList, which will contain the names of all books found in either list, in alphabetical order, with duplicate entries removed. For which of the following lists can a binary search be used to search for an item in the list? Sets found in the same folderSuppose a large group of people in a room were all born in the same year. Consider the following three algorithms, which are each intended to identify the people in the room who have the earliest birthday based on just the month and day. For example, a person born on February 10 is considered to have an earlier birthday than a person born on March 5. Which of the three algorithms will identify the correct people? Sets with similar termsWhat is the most appropriate data type for age?So, we should use integer data type for age.
Which of the following best explains the benefit of using a list as a data abstraction in this situation?Which of the following best explains the benefit of using a list as a data abstraction in this situation? Keeping the numeric values in a list makes it easier to apply the same computation to every data element.
Which of the following best describes the behavior of how pairs of elements are compared?Which of the following best describes the behavior of how pairs of elements are compared? The code segment iterates through myList, comparing each element to all subsequent elements in the list.
What are two advantages of using well named variables?Which of the following are benefits of well-named variables? -The program will be easier to read. -The program will be easier for others to debug.
|