GitHub

@@ -277,9 +277,11 @@ inspect(10, methods=True)

277277278278

In fact there are still more methods, as you can see if you execute `inspect(10, all=True)`.

279279280+281+280282

## A Little Mystery

281283282-

In this lecture we claimed that Python is object oriented.

284+

In this lecture we claimed that Python is, at heart, an object oriented language.

283285284286

But here's an example that looks more procedural.

285287

@@ -289,13 +291,12 @@ m = len(x)

289291

m

290292

```

291293292-

If Python is object oriented, why don't we use `x.len()`? Isn't this

293-

inconsistent?

294+

If Python is object oriented, why don't we use `x.len()`?

294295295-

The answers are related to the fact that Python aims for consistent style.

296+

The answer is related to the fact that Python aims for readability and consistent style.

296297297298

In Python, it is common for users to build custom objects --- we discuss how to

298-

do this [later](python_oop)`.

299+

do this {doc}`later <python_oop>`.

299300300301

It's quite common for users to add methods to their that measure the length of

301302

the object, suitably defined.

@@ -305,10 +306,10 @@ When naming such a method, natural choices are `len()` and `length()`.

305306

If some users choose `len()` and others choose `length()`, then the style will

306307

be inconsistent and harder to remember.

307308308-

To avoid this, the creator of Python chose to have some built-in functions

309-

like `len()`, to make clear that `len()` is the convention.

309+

To avoid this, the creator of Python chose to add

310+

`len()` as a built-in function, to help emphasize that `len()` is the convention.

310311311-

Now, having said all of this, Python still is object oriented under the hood.

312+

Now, having said all of this, Python *is* still object oriented under the hood.

312313313314

In fact, the list `x` discussed above has a method called `__len__()`.

314315

@@ -341,7 +342,8 @@ This includes not just lists, strings, etc., but also less obvious things, such

341342

* files opened for reading or writing

342343

* integers, etc.

343344344-345+

Remember that everything is an object will help you interact with your programs

346+

and write clear Pythonic code.

345347346348

## Exercises

347349

Read the original on github.com ↗