1 | initial version |

For example,

```
P=7*x^3+2*x^4+2
```

you can extract its coefficients as follows:

```
P.coefficients()
```

to get

```
[[2, 0], [7, 3], [2, 4]]
```

So the last sublist contains the answer, in this case 2 is the coefficient of x^4.

To extract this automatically you can define a function that takes a polynomial as argument:

```
def get_highest_coeff(P):
m = P.coefficients()
ncoeffs = len(m)
return m[ncoeffs - 1][0]
```

And use it like this:

```
get_highest_coeff(P)
```

to get 2 as the answer. Hope this helps you get going!

Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.