-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfalse
123 lines (81 loc) · 3.84 KB
/
false
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# Installing and Using VS Code
## Introduction
In this lesson, we will explore Visual Studio Code (VS Code), a powerful
and versatile editor for writing, running, and debugging Python code. VS
Code is widely used due to its rich feature set and extensive extension
library, which makes coding more efficient and enjoyable.
Note that this lesson is better consumed as a video, since there are
many Graphic-user-interface steps that are hard to describe in writing.
## Learning Objectives
By the end of this lesson, you should be able to:
- Open VS Code and navigate to the editor, terminal, and explorer tabs.
- Create a new Python file and run it using the Python extension.
- Use the Command Palette to search for and select a color theme.
## Installing VS Code
VS Code is available for Windows, macOS, and Linux. Search for “VS Code”
in your favorite search engine and go to the official website,
code.visualstudio.com. Download the version for your computer’s
operating system.
For macOs users, after installing VS Code, you may need to drag the icon
to your applications folder.
From your applications folder, open VS Code.
## Navigating the Explorer Tab
The **Explorer** tab displays the files and folders in your current
workspace. When you open VS Code for the first time, it may indicate
that you have not yet opened a folder. Most of our work in Python will
be organized in folders (also known as workspaces) that contain multiple
files.
Let’s create our first workspace:
1. On your computer, navigate to your desktop or another memorable
location.
2. Create a new folder called `first_python_workspace`.
3. In VS Code, click on the **“Open Folder”** button and locate your
newly created folder. Alternatively, you can drag the folder into
the VS Code window.
Now that your workspace is open in VS Code, you can create a new file:
1. In the **Explorer** tab, right-click inside the workspace folder.
2. Select **“New File”**.
3. Name the file `first_script.py`. The file will automatically open in
the editor.
## Writing and Saving Python Code
Let’s write some Python code in your new file:
``` python
print(2 + 2)
```
To save the file, press `Ctrl + S` (or `Cmd + S` on macOS).
## Installing the Python Extension
To run Python code within VS Code, we need to install the Python
extension:
1. Click on the **Extensions** tab on the left sidebar (it looks like
four squares).
2. In the search bar at the top, type **“Python”**.
3. Find the extension named **“Python”** published by Microsoft, and
click **Install**.
## Running Your Python Script
With the Python extension installed, you can now run your script:
1. Open `first_script.py` if it’s not already open.
2. Click on the **Run** icon (a play button) in the top right corner of
the editor.
- Alternatively, you can right-click inside the editor and select
RUn python then **“Run Python File in Terminal”**.
3. A terminal window will open at the bottom of the screen, and your
code will execute. You should see the output:
4
## Using the Command Palette
The **Command Palette** is a powerful feature in VS Code that allows you
to access various commands and settings:
To access it, click on the search bar at the top of vscode window, then
either press \> or select the ‘show and run commands’ option.
Let’s practice changing the color theme:
1. Type ‘theme’ and select ‘Preferences: Color Theme’.
2. Use the up and down arrow keys to cycle through the available color
themes.
3. Press `Enter` to select your preferred theme.
## Wrap Up
In this lesson, we’ve:
- **Installed VS Code** and set up a workspace.
- **Created and saved a Python script**.
- **Installed the Python extension** to enable running and debugging
code.
- **Used the Command Palette** to customize the editor’s appearance.
Happy coding!