-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPython Getting Started.html
More file actions
152 lines (123 loc) · 5.49 KB
/
Copy pathPython Getting Started.html
File metadata and controls
152 lines (123 loc) · 5.49 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Python Getting Started</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
line-height: 1.6;
color: #333;
max-width: 800px;
margin: 0 auto;
padding: 20px;
background-color: #f4f6f8;
}
.container {
background: #ffffff;
padding: 40px;
border-radius: 8px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}
h1 {
color: #1e3a8a;
border-bottom: 2px solid #e5e7eb;
padding-bottom: 12px;
margin-top: 0;
}
h2 {
color: #047857;
margin-top: 30px;
}
p, li {
font-size: 16px;
}
ul {
margin-bottom: 20px;
padding-left: 20px;
}
li {
margin-bottom: 8px;
}
code {
background-color: #f1f5f9;
color: #0f172a;
padding: 2px 6px;
border-radius: 4px;
font-family: "Courier New", Courier, monospace;
font-size: 0.95em;
}
pre {
background-color: #1e293b;
color: #f8fafc;
padding: 16px;
border-radius: 6px;
overflow-x: auto;
font-family: "Courier New", Courier, monospace;
font-size: 0.9em;
}
.file-label {
font-weight: bold;
color: #64748b;
margin-bottom: 4px;
}
a {
color: #2563eb;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<div class="container">
<h1>Python Getting Started</h1>
<h2>Get Started With Python</h2>
<p>At W3Schools, you can try Python without installing anything.</p>
<p>Our Online Python Editor runs directly in your browser, and shows both the code and the result:</p>
<div class="file-label">Example:</div>
<pre><code>print("Hello, World!")</code></pre>
<p>This editor will be used in the entire tutorial to demonstrate the different aspects of Python.</p>
<h2>Python Install</h2>
<p>However, if you want to run Python on your own computer, follow the instructions below.</p>
<p>Many Windows PCs and Mac computers already have Python pre-installed.</p>
<p>To check if Python is installed on Windows, search in the start bar for Python or run the following on the Command Line (<code>cmd.exe</code>):</p>
<pre><code>C:\Users\Your Name>python --version</code></pre>
<p>To check if you have Python installed on Linux or Mac, open the terminal and type:</p>
<pre><code>python --version</code></pre>
<p>If Python is not installed on your computer, you can download it for free from the official website: <a href="https://www.python.org/" target="_blank" rel="noopener">https://www.python.org/</a></p>
<h2>Python Quickstart</h2>
<p>Python is an interpreted programming language, which means that as a developer you write Python (<code>.py</code>) files in a text editor and then put those files into the Python interpreter to be executed.</p>
<p>Let's write our first Python file, called <code>hello.py</code>, which can be done in any text editor:</p>
<div class="file-label">hello.py</div>
<pre><code>print("Hello, World!")</code></pre>
<p>Simple as that. Save your file. Open your command line, navigate to the directory where you saved your file, and run:</p>
<pre><code>C:\Users\Your Name>python hello.py</code></pre>
<p>The output should be:</p>
<pre><code>Hello, World!</code></pre>
<p>Congratulations, you have written and executed your first Python program.</p>
<h2>Python Version</h2>
<p>To check the Python version of the editor, you can find it by importing the <code>sys</code> module:</p>
<div class="file-label">Example:</div>
<pre><code>import sys
print(sys.version)</code></pre>
<p>You will learn more about importing modules in our Python Modules chapter.</p>
<h2>The Python Command Line</h2>
<p>To test a short amount of code in Python, sometimes it is quickest and easiest not to write the code in a file. This is made possible because Python can be run as a command line itself.</p>
<p>Type the following on the Windows, Mac, or Linux command line:</p>
<pre><code>C:\Users\Your Name>python</code></pre>
<p>Or, if the <code>python</code> command did not work, you can try <code>py</code>:</p>
<pre><code>C:\Users\Your Name>py</code></pre>
<p>From there you can write any Python code, including our Hello World example from earlier in the tutorial:</p>
<pre><code>C:\Users\Your Name>python
Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> print("Hello, World!")
Hello, World!</code></pre>
<p>Whenever you are done in the Python command line, you can simply type the following to quit the Python command line interface:</p>
<pre><code>exit()</code></pre>
</div>
</body>
</html>