# Use a question mark after a command to get more info about it
a = [1, 2, 3]
a.extend?

# Use double question marks to get the source code if available
def myfunc(x):
    """ Fancy function """
    return x + 2

myfunc?

myfunc??

"""
Explanation: IPython/Jupyter
Shortcuts
The jupyter notebook interface has a bunch of shortcuts that you can use, but they are not well documented in the webinterface.
Shortcut    | Description
------------|-------------
Enter       | Enter edit mode
Esc         | Enter command mode (escape edit mode)
Tab         | Autocompletion
Shift-Enter | Run cell, select below
Ctrl-Enter  | Run cell
y           | Convert to code cell
m           | Convert to markdown cell
a           | Insert new cell above
b           | Insert new cell below
dd          | Delete cell
There are a lot more schortcuts: (https://sowingseasons.com/blog/reference/2016/01/jupyter-keyboard-shortcuts/23298516)[]
Help
End of explanation
"""


# Magic commands start with a % sign
%timeit print "foo"

# You can add parameters to magic commands, just like you would do for commandline commands
%timeit -n 5 print "foo" # Only do 5 loops, instead of the default 10k

# You can also ask for help for magic commands using the question mark
%timeit?

# See a quick reference of other commands:
%quickref

# There are a lot more specicial commands
%ls # same as linux ls command: list files in directory

# Run an external script
%run myscript.py

# If you forget to store the result of your last statement in a variable, 
# you can always access it using the special underscore variable, like so:
5+3

_

# You can also access previous results by referencing the output number using _X
# where X is the output cell you want to reference:
_39

# Or the input number using _iX
_i36

"""
Explanation: Magic Commands
End of explanation
"""


# You can also easily execute OS commands using !
!ls -lh

output = !ls -lh
output

# You can reference other variables by prefixing them by a dollar sign $
dirname = "/tmp"
!ls $dirname

"""
Explanation: Executing shell commands
End of explanation
"""


