In Python, there are objects and names. An object has a type, a name is just a pointer to an object. If an object doesn't have a name, you cannot access it (in fact, if there are no names pointing to an object, Python will get rid of it altogether).
In other languages, a name is usually called variable and the are declared of a specific type. I have read some books that talk about variables being a box, and the box can only take a certain type of thing, which is the value.
Python works a bit differently. Names which are the equivlant to variables don't have a type. They can point to any object and more specifically any object of any type.
So technically, I guess what I'm asking is: is the parameter 'age' considered an int by python, until the return function changes it into an str type? Note that the assignment wants 4 parameters, 2 strings (which I have), 1 int (which I don't know if it's actually interpreted as an int) and a boolean
Since Python is not strict about types; you usually speak of objects. So when you pass in in a parameter to a function, you are passing in the object which of the integer type.
However, is just a name, and names can point to any type. Since you can pass in any object to the function (in other words, can be any valid Python object), its not correct to say that parameter 'age' is considered an int. Its just a placeholder for any kind of object that is passed to the function.
In the body of your function, you are creating a string object by combining other objects together.
A string object knows what to do when you ask it to be combined with another object - any other object. Since it doesn't know what you'll try and combine with it; it has some sensible defaults and tries to convert stuff to a string.
If it cannot do this combination, it will give you an error:
In that scenario what we want to do is convert the object 2 into a string. To do that for integers, or really - any object at all, we use the method (as you have done correctly).
So what happens when you convert the object to a string, an entirely new object is created - which has no link to the original - and is the string representation of it. This is an entirely new object. A different thing altogether.
I really have no idea how Booleans work. specifically, in the context of the assignment, what exactly am i supposed to do?
The good thing is, once you know how one object works - all objects generally behave the same way. In Python, when you know how to get the string version of one object (by doing ) you use the same technique on every-other-object. It is upto the object to figure out how to "convert" itself.
In other words - since you know that will take an object and convert it to its string representation; you can rest easy that it will work with every other object in Python.
As types are not strict in Python, it gives programmers this flexibility that allows them to rely on the object to know what needs to be done.
That's why works with booleans and int and floats and every other object. Later on in your studies when you start learning about classes (which are ways to create custom objects), you'll learn how to control what happens to your object when someone does a on it.
这次需要代写的作业，考察Python的Unit tests的使用方法，关注测试的code coverage.
In our final exercise of the term, we’re going to be practicing writing UnitTests. The structure of the tests isn’t really as important as the testing plan, but we get to test both.
What to Test
We wanted to come up with a function for you to test that had a bit of everything: loops, selection, lists, strings, dictionaries, objects, etc. But we had a bit of a conundrum. We wanted something complicated enough to be interesting, but knew you were busy with your assignment, and didn’t want everyone to have to spend lots of time writing a new function in order to test it.
That’s when it hit us. You’re already writing a function that you’ll probably want to test anyway… cartesian product! It’s got everything we need, you already have to write it, and now it can help you test your own code for A2. (A pretty smart move if I do say so myself).
How to Start
Before you start writing any code, you should think about coverage testing, and how we came up with a test plan in lecture. Figure out all of the parameters, and the important ranges they fall into. Then write one test for each possible combination of ranges. The goal here is to find one example test case for all possible regions of your testing space.
Most of your actual tests will probably involve code that looks like this (now do you see why we made you write set dict and get dict?
What to Do
In a file called ex10.py, you should write a UnitTest to thoroughly test cartesian product. Your tests will actually be run on a version of the code that I have written. Therefore, you will be doing black box testing (you don’t know if I implemented the cartesian product or the Table class in the same way you will… in fact, you can bet that I probably won’t). My cartesian product function will be in a file called squeal.py, and my Table class will be in a file called database.py. Both will be placed into the same directory as your UnitTest. We’ve provided you with some starter code, just to make sure you can access everything correctly.
What to Submit
Submit your ex10.py file to MarkUs as usual. Your UnitTest methods do not need any DocStrings, and unless you’re doing something particularly unusual, you probably don’t need any internal comments either. However, your method names and error messages should be descriptive enough to properly explain what each test case does and why it’s useful. Remember that writing frivolous test cases is no better than missing useful ones.