Visit Blog
Explore Tumblr blogs with no restrictions, modern design and the best experience.
Fun Fact
There are 44.6 Billion blog posts on Tumblr.
Trending Blogs
#functions

So what do these two functions do?
callable() checks if an object in python is callable as the name suggests but what does that actually mean? What makes an object callable? And what does this hasattr() function do? That’s what I’m going to try to explain in this blog post. ;)

By the way, when I say object, you have to know that everything in Python is an object. So for now know that an integer is an object, a string is an object, a function is also an object just as a datatype like floats are also an object.

An object is always callable if it has the __call__ method in it’s namespace. That’s exactly what callable() does. It checks very specifically if the __call__ method is inside an objects namespace. Not more not less.

If you want to have a look yourself. Just write in the repl the following command: dir(object who’s namespace you want to check) and it will return just that, the namespace of the chosen object.

Here we have asked for the namespace of an integer object and as we can see, it does not have the __call__ method in there. Which means, that it’s not callable and in combination with the callable() function will return “False”.

If we look into the namespace of our function called “func”, it has different items in its namespace than there are in the integer objects namespace, it has the __call__ method in there that we were looking for, so if we were to call the function with a callable() function, it would return True.

hasattr() on the other hand works a bit different as it tells you if an attribute is present in the passed objects namespace. So if you were to say:  hasattr(object of your choice, the attribute that you want the function to look up) This way you could check whether or not the requested attribute is in the objects namespace. if that’s not the case, it will return “False”.

So you see callable() and hasattr() aren’t that different in their core but that callable() is more specific in what it does. So with callable() you can ask if the __call__ function is inside an objects namespace whereas with hasattr() you can ask if an attribute of your choosing is inside a chosen object.

Hopefully this will help you understand those two functions better and what they do.

Until next time. ;)

0 notes
Text

P2 §11.2.9 Exercise 11B Challenge (Reverse chain rule 1)

P2 §11.2.9 Exercise 11B Challenge (Reverse chain rule 1)

Challenge. Given and that and are integers with , find two different pairs of values of and .(Edexcel 2017 Specification, P2 Ch11 Exercise 11B Challenge.)

Solution. We have:

It is given that , i.e.

There are two possibilities to consider:

Possibility #1:

so is a multiple of 4 and $b$ is a multiple of 3 with the opposite signs. The solutions are:

For , we find two pairs: and .

Possibility…

View On WordPress

0 notes
Text

P2 §11.2.8 Exercise 11B Q8 (Reverse chain rule 1)

P2 §11.2.8 Exercise 11B Q8 (Reverse chain rule 1)

Question 8. Given find the exact value of . (7 marks)(Edexcel 2017 Specification, P2 Ch11 Exercise 11B Q8.)

Solution. We have:

It is given that , i.e.

View On WordPress

0 notes
Text

P2 §11.2.7 Exercise 11B Q7 (Reverse chain rule 1)

P2 §11.2.7 Exercise 11B Q7 (Reverse chain rule 1)

Question 7. Given find the value of . (4 marks)(Edexcel 2017 Specification, P2 Ch11 Exercise 11B Q7.)

Solution. We have:

It is given that , i.e.

View On WordPress

0 notes
Text

P2 §11.2.6 Exercise 11B Q6 (Reverse chain rule 1)

P2 §11.2.6 Exercise 11B Q6 (Reverse chain rule 1)

Question 6. Given find the value of . (4 marks)(Edexcel 2017 Specification, P2 Ch11 Exercise 11B Q6.)

Solution. We have:

It is given that , i.e.

View On WordPress

0 notes
Text

P2 §11.2.5 Exercise 11B Q5 (Reverse chain rule 1)

P2 §11.2.5 Exercise 11B Q5 (Reverse chain rule 1)

Question 5. Evaluate: (Edexcel 2017 Specification, P2 Ch11 Exercise 11B Q5.)

Solution.

View On WordPress

0 notes
Text

P2 §11.2.4 Exercise 11B Q4 (Reverse chain rule 1)

P2 §11.2.4 Exercise 11B Q4 (Reverse chain rule 1)

Question 4. Find the following integrals. (Edexcel 2017 Specification, P2 Ch11 Exercise 11B Q4.)

Solution.

View On WordPress

0 notes
Text

P2 §11.2.3 Exercise 11B Q3 (Reverse chain rule 1)

P2 §11.2.3 Exercise 11B Q3 (Reverse chain rule 1)

Question 3. Integrate the following: (Edexcel 2017 Specification, P2 Ch11 Exercise 11B Q3.)

Solution.

View On WordPress

0 notes
Text

P2 §11.2.2 Exercise 11B Q2 (Reverse chain rule 1)

P2 §11.2.2 Exercise 11B Q2 (Reverse chain rule 1)

Question 2. Find the following integrals. (Edexcel 2017 Specification, P2 Ch11 Exercise 11B Q2.)

Solution.

View On WordPress

0 notes
Text

P2 §11.2.1 Exercise 11B Q1 (Reverse chain rule 1)

P2 §11.2.1 Exercise 11B Q1 (Reverse chain rule 1)

Question 1. Integrate the following: (Edexcel 2017 Specification, P2 Ch11 Exercise 11B Q1.)

Solution.

View On WordPress

0 notes
Text

P2 §11.2 Reverse chain rule 1: Integrating f(ax+b)

P2 §11.2 Reverse chain rule 1: Integrating f(ax+b)

1. Reverse chain rule 1: Integrating f(ax+b)

If you know the integral of a function , you can integrate a function of the form

using the reverse of the chain rule for differentiation.

Example 1. Find the following integrals. (Edexcel 2017 Specification, P2 Ch11 Example 3.)

Solution. (a) The derivative of is $\cos x$. So our first guess is and, by chain rule, we find:

(b) The derivative of is…

View On WordPress

0 notes
Text

People always say these 4 are somewhat disconnected from reality, but like… how disconnected from reality are you?

I thought it was low Se playing its usual antics, but INxP have Si in the tertiary place so idk.

Like I have a disconnect between the past and the present. Maybe from looking toward the future too much? I sort of think the past doesn’t matter; I mean of course it matters, but like if you forgot the past it wouldn’t really impact the present… Obviously it does but if you think about it, it’s just the past, it’s not right now, and the future is intangible anyways, yknow? Maybe that doesn’t make much sense. I’m just trying to explain the disconnection.

9 notes
Text

P2 §11.1.7 Exercise Q7 (Integrating standard functions)

P2 §11.1.7 Exercise Q7 (Integrating standard functions)

Question 7. (a) (2 marks) Solve the equation .(b) (2 marks) Find .© (3 marks) Evaluate , giving your answer in the form , where and are rational numbers.(Edexcel 2017 Specification, P2 Ch11 Exercise 11A Q7.)

Solution. (a)

Aside: To be more precise,

is of the form

which factorises as follows:

As we consider the graph of

we notice that it has only one real root, i.e. has no real…

View On WordPress

0 notes
Text

P2 §11.1.6 Exercise Q6 (Integrating standard functions)

P2 §11.1.6 Exercise Q6 (Integrating standard functions)

Question 6. Given find the value of . (4 marks)(Edexcel 2017 Specification, P2 Ch11 Exercise 11A Q6.)

Solution. We have:

Given that , we find:

We see that is a solution. To find other solutions, noting that is a factor,

Hence, is the only real solution.

Aside: The other two solutions are complex numbers – see CP1 §1 Complex numbers.

View On WordPress

0 notes
Text

P2 §11.1.5 Exercise Q5 (Integrating standard functions)

P2 §11.1.5 Exercise Q5 (Integrating standard functions)

Question 5. Given that is a positive constant and find the exact value of . (4 marks)(Edexcel 2017 Specification, P2 Ch11 Exercise 11A Q5.)

Solution. We have:

Given that , this gives:

Since is a positive constant, .

View On WordPress

0 notes
Text

P2 §11.1.4 Exercise Q4 (Integrating standard functions)

P2 §11.1.4 Exercise Q4 (Integrating standard functions)

Question 4. Given that is a positive constant and find the exact value of . (4 marks)(Edexcel 2017 Specification, P2 Ch11 Exercise 11A Q4.)

Solution. We have

which gives

View On WordPress

0 notes
Text

P2 §11.1.3 Exercise Q3 (Integrating standard functions)

P2 §11.1.3 Exercise Q3 (Integrating standard functions)

Question 3. Evaluate the following. Give your answers as exact values. (Edexcel 2017 Specification, P2 Ch11 Exercise 11A Q3.)

Solution.

Note: The standard results for the integrals of trigonometric functions work in radians. When working in degrees, it brings an extra factor of $\frac{180}{\pi}$ for integration and of $\frac{\pi}{180}$ for differentiation – see for example P2 §9.6…

View On WordPress

0 notes
Text

P2 §11.1.2 Exercise Q2 (Integrating standard functions)

P2 §11.1.2 Exercise Q2 (Integrating standard functions)

Question 2. Find the following integrals. (Edexcel 2017 Specification, P2 Ch11 Exercise 11A Q2.)

Solution.

View On WordPress

0 notes
Text

P2 §11.1.1 Exercise Q1 (Integrating standard functions)

P2 §11.1.1 Exercise Q1 (Integrating standard functions)

Question 1. Integrate the following with respect to . (Edexcel 2017 Specification, P2 Ch11 Exercise 11A Q1.)

Solution.

View On WordPress

0 notes
Text

P2 §11.1

1. Integrating standard functions

Integration is the inverse of differentiation. We can use our knowledge of derivatives to integrate familiar functions.