Читать книгу Algorithms For Dummies - John Paul Mueller, John Mueller Paul, Luca Massaron - Страница 70
Creating code cells
ОглавлениеThe first cell that Colab creates for you is a code cell. Colab and Notebook share the same features with regard to code, so code you write in Colab also works in Notepad (and vice versa). However, off to the side of the cell, you see a menu of extras that you can use with Colab (see Figure 3-9); these aren’t present in Notebook.
FIGURE 3-9: Colab code cells contain a few extras not found in Notebook.
You use the icons shown in Figure 3-9 to augment your Colab code experience. Here’s what these features do (in order of appearance, left to right, in the figure):
Move cell up: Moves the cell up one position in the cell hierarchy.
Move cell down: Moves the cell down one position in the cell hierarchy.
Link to cell: Displays a dialog box containing a link you can use to access a specific cell within the notebook. You can embed this link anywhere on a web page or within a notebook to allow someone to access that specific cell. The person still sees the entire notebook but doesn’t have to search for the cell you want to discuss.
(Optional) Add a comment (assuming that you have the right to make a comment): Creates a comment balloon to the right of the cell. This is not the same as a code comment, which exists inline with the code but affects the entire cell. You can edit, delete, or resolve comments. A resolved comment is one that receives attention and is no longer applicable.
Open editor settings: Opens the same dialog box shown in Figure 3-2 and discussed in the “Getting familiar with Google Colab features” section, earlier in this chapter. You need to select some code before this option appears.
Mirror cell in tab: Mirrors the currently selected cell in a Cell pane that appears on the right side of the window. You can scroll wherever you want within the code in the left pane and keep this code accessible. The right-pointing arrow lets you execute the cell at any time after making changes in left-pane code. A pair of double-pointing arrows lets you move the focus back to the selected code in the left pane with a single click. You can also move the cell code to a scratch cell, where you can play with it without modifying your original code. You can have more than one Cell pane. You simply select the one you want and move between them as needed, which lets you move easily from place to place in your code. Close a Cell pane by clicking the X next to the word Cell.
Delete Cell: Removes the cell from the notebook.
Vertical ellipses: Contains a number of additional features in a menu (not all of which may appear because they depend on the file you have opened, the tasks you have performed, and your rights to work with the file content):Copy Cell: Copies the content of the currently selected cell to the clipboard.Cut Cell: Deletes the content of the currently selected cell and places it on the Clipboard.Clear Output: Removes the output from the cell. You must run the code again to regenerate the output.View Output Fullscreen: Displays the output (not the entire cell or any other part of the notebook) in full-screen mode on the host device. This option is useful when displaying a significant amount of content, or when a detailed view of graphics helps explain a topic. Press Esc to exit full-screen mode.Add a Form: Inserts a form into the cell to the right of the code. You use forms to provide a graphical input for parameters. Forms don’t appear in Notebook, but because of how you create them, they won’t prevent you from running the code in Notebook. You can read more about forms at
https://colab.research.google.com/notebooks/forms.ipynb
.
Code cells also tell you about the code and its execution. The little icon next to the output displays information about the execution when you hover your mouse over it. Clicking the icon clears the output. You must run the code again to regenerate the output.