<commit_before>First of all you need to pull the various netaddr classes and functions into your namespace.

.. note:: Do this for the purpose of this tutorial only. In your own code, you should be explicit about the classes, functions and constants you import to avoid name clashes.

>>> from netaddr import *

We also import the standard library module `pprint` to help format our output.

>>> import pprint

----------------
Basic operations
----------------

The following `IPAddress` object represents a single IP address.

>>> ip = IPAddress('192.0.2.1')
>>> ip.version
4

The `repr()` call returns a Python statement that can be used to reconstruct an equivalent IP address object state from scratch when run in the Python interpreter.

>>> repr(ip)
"IPAddress('192.0.2.1')"
>>> ip
IPAddress('192.0.2.1')

Access in the string context returns the IP object as a string value.

>>> str(ip)
'192.0.2.1'
>>> '%s' % ip
'192.0.2.1'
>>> ip.format()  # only really useful for IPv6 addresses.
'192.0.2.1'

------------------------
Numerical representation
------------------------

You can view an IP address in various other formats.

>>> int(ip) == 3221225985
True
>>> hex(ip)
'0xc0000201'
>>> ip.bin
'0b11000000000000000000001000000001'
>>> ip.bits()
'11000000.00000000.00000010.00000001'
>>> ip.words == (192, 0, 2, 1)
True

---------------------------------
Representing networks and subnets
---------------------------------

`IPNetwork` objects are used to represent subnets, networks or VLANs that accept CIDR prefixes and netmasks.

>>> ip = IPNetwork('192.0.2.1')
>>> ip.ip
IPAddress('192.0.2.1')
>>> ip.network, ip.broadcast
(IPAddress('192.0.2.1'), IPAddress('192.0.2.1'))
>>> ip.netmask, ip.hostmask
(IPAddress('255.255.255.255'), IPAddress('0.0.0.0'))
>>> ip.size<commit_msg>- fixed bug in tutorial based on change in this release<commit_after>First of all you need to pull the various netaddr classes and functions into your namespace.

.. note:: Do this for the purpose of this tutorial only. In your own code, you should be explicit about the classes, functions and constants you import to avoid name clashes.

>>> from netaddr import *

We also import the standard library module `pprint` to help format our output.

>>> import pprint

----------------
Basic operations
----------------

The following `IPAddress` object represents a single IP address.

>>> ip = IPAddress('192.0.2.1')
>>> ip.version
4

The `repr()` call returns a Python statement that can be used to reconstruct an equivalent IP address object state from scratch when run in the Python interpreter.

>>> repr(ip)
"IPAddress('192.0.2.1')"
>>> ip
IPAddress('192.0.2.1')

Access in the string context returns the IP object as a string value.

>>> str(ip)
'192.0.2.1'
>>> '%s' % ip
'192.0.2.1'
>>> ip.format()  # only really useful for IPv6 addresses.
'192.0.2.1'

------------------------
Numerical representation
------------------------

You can view an IP address in various other formats.

>>> int(ip) == 3221225985
True
>>> hex(ip)
'0xc0000201'
>>> ip.bin
'0b11000000000000000000001000000001'
>>> ip.bits()
'11000000.00000000.00000010.00000001'
>>> ip.words == (192, 0, 2, 1)
True

---------------------------------
Representing networks and subnets
---------------------------------

`IPNetwork` objects are used to represent subnets, networks or VLANs that accept CIDR prefixes and netmasks.

>>> ip = IPNetwork('192.0.2.1')
>>> ip.ip
IPAddress('192.0.2.1')
>>> ip.network, ip.broadcast
(IPAddress('192.0.2.1'), None)
>>> ip.netmask, ip.hostmask
(IPAddress('255.255.255.255'), IPAddress('0.0.0.0'))
>>> ip.size
{'fraction_non_alphanumeric': 0.2038888888888889, 'fraction_numerical': 0.09111111111111111, 'mean_word_length': 2.9269356597600873, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 117, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 23, 'substrings_counts': 8, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7195450', 'n_tokens_mistral': 1292, 'n_tokens_neox': 1076, 'n_words': 401}