PracticalStuff Flashcards
Help on the len function
len?, len??
Create a docstring
Place a string literal in the first line
sometimes the ?? suffix doesn’t display any source code
T object in question is not implemented in Python, but in C or ..
List every object in the namespace that ends with Warning
*Warning?
Find a string method that contains the word find somewhere in its name.
str.find?
Make a list of the first 1000 squares, timing it.
%timeit L = [n ** 2 for n in range(1000)]
Time steps in a for-loop:
%%timeit
…: L = []
…: for n in range(1000):
…: L.append(n ** 2)
Side-by-side subplots:
plt.subplot(221)
p1=plt.hist(ldh_vals.ord_num_value,bins=20,log=False)
plt.subplot(222)
p2=plt.hist(ldh_vals.ord_num_value,bins=20,log=True)
plt.show()
List of all magic functions
%lsmagic
Help on %timeit
%timeit?
List the IPython lines so far:
print(In)
List the Cell outputs so far
print(Out)
You execute two very expensive computations in cells 2 and 3. You want to the results of 2 and 3.
Out[2] ** 2 + Out[3] ** 2
Accessing previous output,
the second-to-last output, to access the third-to-last output
_
__
___
Suppress the output of a command is to
add a semicolon to the end
In [14]: math.sin(2) + math.cos(2);
result is computed silently, and the output is neither displayed on the screen or stored in the Out dictionary: