-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
241 lines (212 loc) · 13.2 KB
/
Copy pathindex.html
File metadata and controls
241 lines (212 loc) · 13.2 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
<!DOCTYPE html>
<html lang="en">
<link href="index.css" type="text/css" rel="stylesheet"/>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Python</title>
</head>
<body>
<main id="main-doc" >
<h1>Python</h1>
<section class="main-section"id="Introduction">
<header >Introduction</header>
<p>Python is an open source language that is getting a lot of attention from the
market. It combines ease of use with the capability to run on multiple platforms
because it is implemented focusing on every major operating system.</p>
<p>Guido van Rossum created the language nearly 11 years ago and since then,
Python has changed through the years, turning itself into one of the most
powerful programming languages currently available.</P>
<p> Python is a good prototype language. In just a few minutes, you can develop
prototypes that would take you several hours in other languages.</P>
<p> It also embodies all object-oriented concepts as part of its core engine.
Therefore, creating programming object-oriented applications in Python is
much easier than it would be in other languages such as Java or C++.</p>
<p>As I just said, Python is an open source project. Consequently,
it is truly free. No copylefts or copyrights are involved in its
license agreement. You can change it, modify it, give it away, sell it,
and even freely distribute it for commercial use. Its copyright only protects
the author from legal problems that might occur if someone decides to sue
the author for errors caused by using Python, or if someone else tries to
claim ownership of the language. Maybe you still don't know Python,
but many companies are out there using it. The problem is these companies
don't want to go public talking about it because they think that using Python
without getting the attention of their competitors is a good strategy.</p>
Okay, I know that you are curious to know who in the world is using Python.
Organizations like Industrial Light and Magic, Yahoo!, Red Hat,
and NASA are some of companies that run Python applications.</p>
</section>
<section class="main-section"id="Hello_World">
<header >Hello World</header>
<code> print("hello world")</code>
</section>
<section class="main-section" id="Built_in_Data_Types">
<header > <br>Built in Data Types</header>
<p>Built-in data types are types that are already built into the interpreter.
They are divided into two groups:</p>
<p> Immutable Data Types These objects cannot have their values altered
(for example, strings, numbers, and tuples).
Mutable Data Types These objects can have their values manipulated
(for example, lists and dictionaries). Sometimes, it becomes necessary
to assign a null value to a variable using the special data type known
as None:</p>
<code> >>> x = 1 >>> x 1 >>> print x 1 >>> x = None >>> x >>></code>
<p> As you could see, nothing was returned. However, if you try to print this
value, the print method of the object will specially handle the None
value by returning a None result. This is shown in the following:</p>
<code> >>> print x None</code>
</section>
<section class="main-section" id="Strings" >
<header><br>Strings</header>
<p>Python considers a string as a sequence of characters.
Therefore, every time you use, for example, the string "Parrot",
internally Python handles it as the sequence ["P", "a", "r", "r", "o", "t"].</p>
<p>The first indexer value is always the number zero. Hence, to have access to the
letter P, you need to say "Parrot"[0] and to access the letter a,
you need to say "Parrot"[1]. Using the same concept, we can get access
to all the other elements. The following is an example of string operators:</p>
<code> >>> "dead parrot " + "sketch" </code>
<code> # concatenation "dead parrot sketch" >>> "parrot " * 2 </code>
<code> # repetition "parrot parrot" >>> "parrot"[1] </code>
<code># indexing "a" >>> "parrot"[-1] </code>
<code># indexing backward "t" >>> "parrot"[1:3]</code>
<code> # slicing (*) "ar" </code>
</section>
<section class="main-section"id="Built_in_Functions">
<header ><br>Built in Functions</header>
<p>The following functions are always available when you load the Python
interpreter. You don't need to import them because they are already part
of the __builtin__ module, which is always imported when you launch Python.
apply() It executes a given function, passing the arguments provided.
basic syntax: apply(function, (tuple of positional arguments)
[, dictionary of keywords arguments])</p>
<code> >>> apply (raise_salary, (6000), {'employee':'John', 'id':13})</code>
<p>Note that starting at Python 1.6, the functionality of apply
is now available with normal function calling, such as</p>
<code> >>> args = (6000,) >>> kwargs = { 'employee':'John', 'id':13} </code>
<code> >>> raise_salary(*args, **kwargs) coerce()</code>
<p> coerce is used to try to convert the two given arguments x
and y to the same type, returning them as a tuple. basic syntax:</p>
<code> coerce( x, y ) >>> coerce(42,5.4) (42.0, 5.4) filter() </code>
<p> It creates a new list by taking each element of list for which
function evaluates to true. basic syntax:
filter( function, list ) >>> a = range (4)</p>
<code> >>> b = filter(lambda x: x < 3, a)</code>
<code> >>> print b [0,1,2] globals() </code>
<p>It returns the global namespace dictionary. basic syntax:</p>
<code> globals() input() </code>
<p>It provides an input interface for the user.
Only numbers are accepted. basic syntax: </p>
<code>put( [prompt] ) a = input("Please, type a number greater than 5: ")</code>
<code> if a<5: print "a is not greater than 5" locals() </code>
<p>It returns the local namespace dictionary basic syntax:</p>
<code> locals() map() </code>
<p>It applies a function to each element of list, producing another list.
If function is set to None and multiple lists are provided, a tuple
matrix is generated in the format of a list. basic syntax: </p>
<code> map( function, list ) >>> lst = map(None, [1,2,3,4], [1,2,3,4,5,6])
>>> lst [(1, 1), (2, 2), (3, 3), (4, 4), (None, 5), (None, 6)] open() </code>
<p>It opens a file. (See the section "File Handling" for details.) basic syntax:</P>
<code>open( filename [,mode [,bufsize]] ) pow() </code>
<p>It returns x**y or (x**y) % z, depending on the number of arguments
that are transported.basic syntax:</p>
<code> pow( x, y [,z] ) raw_input() </code>
<p>It reads from standard input ( sys.stdin ), returning the read data as
a string. prompt is an optional text that can be displayed in the screen.
basic syntax: </p>
<code> raw_input( [prompt] ) reduce() </code>
<p>It applies a function
cumulatively to the items in sequence (implied loop), returning a single
value. initializer is an optional starting value. basic syntax:</p>
<code> reduce( function, sequence [,initializer] )</code>
<p>>>> import operator >>> a = [1,2,3] >>> print reduce(operator.add, a)
6 The equivalent Python code for this function is something like def
reduce(func, list): ret = list[0] for x in list[1:]: </p>
<code> ret = func(ret, x) return ret __import__() </code>
<p>This is a function invoked by the import statement. To import a module, you
just need to inform the module name. basic syntax:</p>
<code> __import__( module_name [,globals() [, locals() [,from list]]] )
>>> modname = "string" >>> string = __import__(modname) >>> string reload()</code>
<p>It reloads an already imported module. Internally, it calls the __import__
function. basic syntax:</p>
<code> reload( module ) </code><br>
</section>
<section class="main-section"id="Control_Statements">
<header ><br>Control Statements</header>
<p>Python implements all the necessary types of control statements that your program might require.
The syntax provided by Python's if, for, and while statements should be enough for your needs.
Tip Remember to type a colon at the end of each line where you enter a statement declaration.
if/elif/else The general syntax for the if/elif/else statement is as follows:</p>
<ul>
<li>1: if < condition >:</li>
<li>2: < statements ></li>
<li>3: [elif < condition >:</li>
<li>4: < statements >] </li>
<li>5: [elif < condition >: {}</li>
<li>6: pass] </li>
<li>7: …</li>
<li>8: [else:</li>
<li> 9: < statements >]</li>
</ul>
<p>Note that both elif and else clauses are optional.
As you can see in lines 3 through 7, it is only necessary to use elif when you need
to handle multiple cases. That is exactly how you implement
the switch/case statements from other languages. </p>
</section>
<section class="main-section"id="Data_Structures">
<header >Data Structures</header>
<p>Python implements a variety of data structures, such as lists, tuples, ranges,
and dictionaries (also known as hash tables ).</p>
<p>Lists </p>
<p> Lists are mutable
sequences of objects indexed by natural numbers that can be changed after
they are created. Lists are very flexible and easy to create.
They are always enclosed in brackets:</p>
<code> >>> lst = [1,2,3,4]</code> <p> # this is simple list</p>
<p>Ranges A range is an actual list of integers. The built-in
function range() provides this data structure.</p>
<code> >>> r = range(2,5) </code>
<code>>>> print r</code>
<code>[2,3,4]</code>
<p>When the first argument is left out, it is assumed to be zero.</p>
<p>Tuples </p>
<p>A tuple is a sequence of immutable Python objects.
The general syntax of a tuple is as follows: variable =</p>
<code> (element1, element2, …)</code>
<p>Dictionaries ( hash tables )</p>
<p> Dictionaries illustrate the only mapping type
of Python. They represent finite sets of objects indexed by nearly arbitrary
values. I say nearly because dictionary keys cannot be variables of mutable
type, which are compared by value rather than by object identity.
Python dictionaries are also known as associative arrays or hash tables.
The general syntax of a dictionary is as follows: variable =</p>
<code>{" key1 ":" value1 ", " key2 ":" value2 ", …} </code>
<p>Dictionaries are always enclosed in braces. They associate key
elements with value elements—keys and values are displayed separated
by a colon. The values of a dictionary can be of any type, but the keys
must be of an immutable data type (such as strings, numbers, or tuples).
Dictionary keys have no natural order and are always listed in arbitrary
order because it uses a hash technique to implement a fast lookup.</p>
</section>
<section class="main-section" id="Reference">
<header>Reference</header>
<p>I've taken this text from 'The Python Developers Handbook' by André Dos Santos Lessa
it was written in 2000 and covers Python 2.0 and is not up to date with the current version of Python</p>
</section>
</main>
<nav id="navbar">
<header id="nav-header"><h2>Python</h2>
<ul class="flexbox">
<li><a href="#Introduction" class="nav-link">Introduction</a></li>
<li><a href="#Hello_World" class="nav-link">Hello World</a></li>
<li><a href="#Built_in_Data_Types" class="nav-link">Built in Data Types</a></li>
<li><a href="#Strings" class="nav-link">Strings</a></li>
<li><a href="#Built_in_Functions" class="nav-link">Built in Functions</a></li>
<li><a href="#Control_Statements" class="nav-link">Control Statements</a></li>
<li><a href="#Data_Structures" class="nav-link">Data Structures</a></li>
<li><a href="#Reference" class="nav-link">Reference</a></li>
</ul></nav>
</header>
</body>
</html>