You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
product_of_elems = functools.reduce(<spanclass="hljs-keyword">lambda</span> out, x: out * x, <collection>)
238
238
list_of_chars = list(<str>)
239
239
</code></pre>
240
-
<pre><codeclass="python language-python hljs">index = <list>.index(<el>) <spanclass="hljs-comment"># Returns first index of item.</span>
240
+
<pre><codeclass="python language-python hljs">index = <list>.index(<el>) <spanclass="hljs-comment"># Returns first index of item or raises ValueError.</span>
241
241
<list>.insert(index, <el>) <spanclass="hljs-comment"># Inserts item at index and moves the rest to the right.</span>
242
242
<el> = <list>.pop([index]) <spanclass="hljs-comment"># Removes and returns item at index or from the end.</span>
243
243
<list>.remove(<el>) <spanclass="hljs-comment"># Removes first occurrence of item or raises ValueError.</span>
<pre><codeclass="python language-python hljs"><str> = <str>.strip() <spanclass="hljs-comment"># Strips all whitespace characters from both ends.</span>
378
378
<str> = <str>.strip(<spanclass="hljs-string">'<chars>'</span>) <spanclass="hljs-comment"># Strips all passed characters from both ends.</span>
379
379
</code></pre>
380
-
<pre><codeclass="python language-python hljs"><list> = <str>.split() <spanclass="hljs-comment"># Splits on any whitespace character.</span>
380
+
<pre><codeclass="python language-python hljs"><list> = <str>.split() <spanclass="hljs-comment"># Splits on one or more whitespace characters.</span>
381
381
<list> = <str>.split(sep=<spanclass="hljs-keyword">None</span>, maxsplit=<spanclass="hljs-number">-1</span>) <spanclass="hljs-comment"># Splits on 'sep' str at most 'maxsplit' times.</span>
382
+
<list> = <str>.splitlines(keepends=<spanclass="hljs-keyword">False</span>) <spanclass="hljs-comment"># Splits on line breaks. Keeps them if 'keepends'.</span>
382
383
<str> = <str>.join(<collection>) <spanclass="hljs-comment"># Joins elements using string as separator.</span>
383
384
</code></pre>
384
385
<pre><codeclass="python language-python hljs"><str> = <str>.replace(old, new [, count]) <spanclass="hljs-comment"># Replaces 'old' with 'new' at most 'count' times.</span>
385
386
<bool> = <str>.startswith(<sub_str>) <spanclass="hljs-comment"># Pass tuple of strings for multiple options.</span>
386
387
<bool> = <str>.endswith(<sub_str>) <spanclass="hljs-comment"># Pass tuple of strings for multiple options.</span>
387
-
<int> = <str>.index(<sub_str>) <spanclass="hljs-comment"># Returns start index of first match.</span>
388
+
<int> = <str>.find(<sub_str>) <spanclass="hljs-comment"># Returns start index of first match or -1.</span>
389
+
<int> = <str>.index(<sub_str>) <spanclass="hljs-comment"># Same but raises ValueError.</span>
388
390
</code></pre>
389
391
<pre><codeclass="python language-python hljs"><bool> = <str>.isnumeric() <spanclass="hljs-comment"># True if str contains only numeric characters.</span>
390
392
<list> = textwrap.wrap(<str>, width) <spanclass="hljs-comment"># Nicely breaks string into lines.</span>
0 commit comments