Skip to main content

Built-in Fonction

Project description

Rédiger « Angosso.jpg » $angosso.net s[i] = x item i of s is replaced by x s[i:j] = t slice of s from i to j is replaced by the contents of the iterable t del s[i:j] same as s[i:j] = [] s[i:j:k] = t the elements of s[i:j:k] are replaced by those of t (1) del s[i:j:k] removes the elements of s[i:j:k] from the list s.append(x) same as s[len(s):len(s)] = [x] (2) s.extend(x) same as s[len(s):len(s)] = x (3) s.count(x) return number of i‘s for which s[i] == x s.index(x[, i[, j]]) return smallest k such that s[k] == x and i <= k < j (4) s.insert(i, x) same as s[i:i] = [x] (5) s.pop([i]) same as x = s[i]; del s[i]; return x (6) s.remove(x) same as del s[s.index(x)] (4) s.reverse() reverses the items of s in place (7) s.sort([cmp[, key[, reverse]]])

>>> from string import Template
>>> s = Template('$who likes $what')
>>> s.substitute(who='angosso', what='ubuntu NIS')
'angosso likes ubuntu NIS'
>>> d = dict(who='angosso')
>>> Template('Give $who $100').substitute(d)
Traceback (most recent call last):
[...]
ValueError: Invalid placeholder in string: line 1, col 10
>>> Template('$who likes $what').substitute(d)
Traceback (most recent call last):
[...]
KeyError: 'what'
>>> Template('$who likes $what').safe_substitute(d)
'angosso likes $what'

Project details


Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page