I am reading through the Python tutorials and I have ...
I am reading through the Python tutorials and I have reached the part where parameter definitions begin with "*" or "**" UNARY. I have looked around a little and some places it says it's an operator, but I am still unsure how to use this. What does this mean? UNARY "*" allows for a variable number of arguments, all arguments to right must use argument name when calling UNARY "**" allows for dictionary to be passed for arguments, the dictionary keys are argument names, the dictionary values are argiument values Binary * is mult Binary ** exponent
I'm starting to understand what a dictionary is and how it differs from an array, but in what scenarios would you really want to use a dictionary over a regular array? Key is non int
Why do we need tuples and dictionaries and arrays and lists? Different problem requirements
Does Python have internal classes like Java does, and if so, how do you declare them? YES, we will see how to import and use the Python API
Is there any way to guarantee that data will be a certain data type similar to a type declaration in Java? At runtime the type is determined
Is there a way to catch a specific exception in Python, and have a specific body of code be executed if that specific exception is caught? (Similar to a try {} catch (Exception e) {} in Java) YES
Given that a lambda is a small anonymous function, why would it be useful to have a nameless function in a class? Argument list functions
In reference to inheritance, can you inherit a constructor? YES
Does python enable/allow polymorphism in the context of inheritance? YES
What is the purpose of pass statements? In the text, it states that it does nothing, so why include it in your code? When would be an occasion where we would practically use pass? If I'm understanding it correctly, it seems redundant to just placing a comment. When we have a block that temporarily needs a statement, comment is not enough
What are some situations/problems where you would use tuples IMMUTABLE over lists MUTABLE or vice versa? Different problem requriements
Does python have different types of classes like Java, like static or abstract? Or interface methods? YES YES YES
Is there a way to increment like ++ from Java? NO a+=1
How are dictionaries or lists compared with greater than operators? Must be same length, then compare element by element for greater than on each one
Since certain programs in Python are easier to code than in Java and consume much less time, why would someone choose to program in Java? Considering they're both object-oriented programming languages, is it because Java isn't as "dynamic" as Python? Python is not limited to OO. Java being compiled and portable, Python interpreted and portable
Professor Bauer mentioned that Java worked well with AI systems due to the characteristics of objects in Java. Wouldn't Python also be considered a language that's meant to program AI systems . . . in fact, wouldn't it be much better because Python isn't using static types like Java and the constraints while coding is significantly less? I said OO was an AI topic originally, not that java is good for AI
Certain data types in Python are mutable, but why is it that data types such as int, String, and tuple are immutable data types? Design choice to ease the implementation of immutable data types
How can we insert a range of elements in the middle of the list? For example: a = [a,b,c,d,e] and I want to add [g,h,i,j,k] between the element "c" and "d" from the list "a" how can we do that? Need to iterate the second and insert one at a time
Can dictionaries append elements? Use update Like we can do with a list. Also can we delete elements from a dictionary? Use del
Can a dictionary have multiple dimensions like we can do with arrays? Yes you can have a dictionary whose values are also dictionaries If so how do we reference the elements in the dictionary? Use [] or get
Does the fact that you can make a method with default argument values mean that there is no need for overloading in Python? Yes
Is there any practical use for the pass function aside from serving as filler during development? Not really
Are all functions able to be used as objects or are there certain ones that are blacklisted from that functionality? Not that I am aware of
If self is virtually always used, why does it have to be explicitly stated as a parameter? Only needed for instance methods, design choice
Does lambda in Python come from lambda calculus? yes
Do all default functions in Python have an associated docstring? yes
Are list comprehensions(and they by generators) faster than regular for loops, and if so why? Yes, List comprehensions are known to perform, in general, better than for loops as they do not need to call the append function at each iteration.
List can be used as stacks and queues, what is the benefit of using the queue and lifoqueue classes over list? Later in term
Are there any data structures that we will need to create classes for? We will for many, see syllabus
Why is 'del' a reserved word in python and why is it used instead of a method or function that list or whatever implements? They wanted to make del like an operator
When should my intuition tell me to use a lambda expression? If you only need to function to pass as an argument to another function. It is never called otherwise
Why would you use a restrictive tuple instead of a list? If the data is immutable
For 9.2.1 Scopes and Namespace Examples, I understand that in def do_nonlocal() has a nonlocal statement and therefore can change the binding of spam, but I am confused to as why do_local(): isn't capable as well,can you please explain? Outside of scope of CS331
For dictionaries, what if you wanted to add multiple values for a unique key, i.e. since there have been multiple Batmans, what if I wanted Bruce Wayne, and Dick Grayson for 'Batman'? use a list for the values
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- chapter 5 functions and parameter passing
- i am reading through the python tutorials and i have
- the function of functions python programming introduction
- 1 functions in python
- pass by object reference in python university of tulsa
- programming principles in python csci 503
- 3 1 system calls
- ppyytthhoonn ffuunnccttiioonnss tutorialspoint
- working with functions in python
- python function basics introduction