<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Pythonic APIs
Step1:  Sizing with len()
Step2:  Arithmetic
Step3:  A simple but full-featured Pythonic class
String formatting mini-language
<ASSISTANT_TASK:>
Python Code:
s = 'Fluent'
L = [10, 20, 30, 40, 50]
print(list(s))  # list constructor iterates over its argument
a, b, *middle, c = L  # tuple unpacking iterates over right side
print((a, b, c))
for i in L:
    print(i, end=' ')
Explanation: Pythonic APIs: the workshop notebook
Tutorial overview
Introduction
A simple but full-featured Pythonic class
Exercise: custom formatting and alternate constructor
A Pythonic sequence
Exercise: implementing sequence behavior
Coffee break
A Pythonic sequence (continued)
Exercise: custom formatting
Operator overloading
Exercise: implement @ for dot product
Wrap-up
What is Pythonic?
Pythonic code is concise and expressive. It leverages Python features and idioms to acomplish maximum effect with minimum effort, without being unreadable. It uses the language as it's designed to be used, so it is most readable to the fluent Pythonista.
Real example 1: the requests API
requests is pleasant HTTP client library. It's great but it would be awesome if it was asynchronous (but could it be pleasant and asynchronous at the same time?). The examples below are from Kenneth Reitz, the author of requests (source).
Pythonic, using requests
```python
import requests
r = requests.get('https://api.github.com', auth=('user', 'pass'))
print r.status_code
print r.headers['content-type']
------
200
'application/json'
```
Unpythonic, using urllib2
```python
import urllib2
gh_url = 'https://api.github.com'
req = urllib2.Request(gh_url)
password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm()
password_manager.add_password(None, gh_url, 'user', 'pass')
auth_manager = urllib2.HTTPBasicAuthHandler(password_manager)
opener = urllib2.build_opener(auth_manager)
urllib2.install_opener(opener)
handler = urllib2.urlopen(req)
print handler.getcode()
print handler.headers.getheader('content-type')
------
200
'application/json'
```
Real example 2: classes are optional in py.test and nosetests
Features of idiomaitc Python APIs
Let the user apply previous knowledge of the standard types and operations
Make it easy to leverage existing libraries
Come with “batteries included”
Use duck typing for enhanced interoperation with user-defined types
Provide ready to use objects (no instantiation needed)
Don't require subclassing for basic usage
Leverage standard language objects: containers, functions, classes, modules
Make proper use of the Data Model (i.e. special methods)
Introduction
One of the keys to consistent, Pythonic, behavior in Python is understanding and leveraging the Data Model. The Python Data Model defines standard APIs which enable...
Iteration
End of explanation
len(s), len(L)
s.__len__(), L.__len__()
Explanation: Sizing with len()
End of explanation
a = 2
b = 3
a * b, a.__mul__(b)
L = [1, 2, 3]
L.append(L)
L
Explanation: Arithmetic
End of explanation
x = 2**.5
x
format(x, '.3f')
from datetime import datetime
agora = datetime.now()
print(agora)
print(format(agora, '%H:%M'))
'{1:%H}... {0:.3f}!'.format(x, agora)
Explanation: A simple but full-featured Pythonic class
String formatting mini-language
End of explanation
<END_TASK>