Everything is an Object (in Python).

The concept of ‘mutability’ (hence: mutants) will actually be relevant for this article.

Types:

>>> a = 1
```>>> a = 1>>> type(a)<class ‘int’>
>>> a = “pepe”>>> type(a)<class ‘str’>

Identity:

>>> a = 1>>> id(a)2149256685872
>>> a = 12>>> b = 21>>> a is bFalse
>>> a = 12>>> b = 21>>> a is bFalse>>> a is not bTrue

Immutable objects.

An example of an immutable object (everything is an object).
>>> a = 10>>> b = 10>>> a is bTrue>>> id(a)1469277170256>>> id(b)1469277170256
>>> a = 13>>> b = a>>> a is bTrue>>> id(a)1573613824688>>> id(b)1573613824688
>>> a = "Pepe">>> b = "Pepe">>> a is bTrue>>>
```>>> a = 15>>> id(a)1573613824752>>> a = 15 + 1>>> id(a)1573613824784

Mutable objects:

Example of mutable object (EVERYTHING is an object!)
>>> list_1 = [1, 2, 3]>>> list_2 = [1, 2, 3]>>> list_1 is list_2False>>> list_1 == list_2True>>> id(list_1)1573654126208>>> id(list_2)1573654942080
>>> list = [1, 2, 3]>>> id(list)1573654931968>>> list.append(4)>>> print(list)[1, 2, 3, 4]>>> id(list)1573654931968

A word about Tuples.

>>> tuple = (1, [2, 3])
>>> tuple = (1, [2, 3])>>> id(tuple)1573654891712>>> tuple[1].append(4)>>> print(tuple)(1, [2, 3, 4])>>> id(tuple)1573654891712

Why should I care?

>>> def increment(n):>>> ... n += 1
>>> x = 1>>> n = x>>> n += 1>>> x1>>> n2

Finally:

>>> x = 256>>> y = 256>>> x is yTrue
>>> x = 257>>> y = 257>>> x is yFalse>>>
Wait, what???

RECAP:

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Automating security alerting with ElastAlert and Cortex XSOAR

SecDevOps Becomes the Extended Security Version of DevSecOps Platform

15 CSS Gradients Examples and Gradient Code

Background Gradient

How to Design a Responsive Kiosk User Interface — Part 1

How to Set Up Jira and Confluence Better Than Expected

Deal with `NullPointerException` with Java8 Optional

Progressive Web Apps. The way to reach your mobile customers

Motivation management for Cloud cost

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Flavio Orlando

Flavio Orlando

More from Medium

JS-05 — JavaScript for Programmers, Chapter4to6, Summary, Part1

Home Loan Status Prediction Using Logistic Regression

Simple array sum HackerRank

Recognizing Handwritten Digits with Scikit-Learn