blob: b279f71180381f4bcd089fe2ba5f03210df9a57a [file] [log] [blame]
Georg Brandl116aa622007-08-15 14:28:22 +00001.. _tut-informal:
2
3**********************************
4An Informal Introduction to Python
5**********************************
6
7In the following examples, input and output are distinguished by the presence or
8absence of prompts (``>>>`` and ``...``): to repeat the example, you must type
9everything after the prompt, when the prompt appears; lines that do not begin
10with a prompt are output from the interpreter. Note that a secondary prompt on a
11line by itself in an example means you must type a blank line; this is used to
12end a multi-line command.
13
Georg Brandl116aa622007-08-15 14:28:22 +000014Many of the examples in this manual, even those entered at the interactive
15prompt, include comments. Comments in Python start with the hash character,
Georg Brandl5d955ed2008-09-13 17:18:21 +000016``#``, and extend to the end of the physical line. A comment may appear at the
17start of a line or following whitespace or code, but not within a string
Christian Heimes5b5e81c2007-12-31 16:14:33 +000018literal. A hash character within a string literal is just a hash character.
Georg Brandl5d955ed2008-09-13 17:18:21 +000019Since comments are to clarify code and are not interpreted by Python, they may
20be omitted when typing in examples.
Georg Brandl116aa622007-08-15 14:28:22 +000021
22Some examples::
23
24 # this is the first comment
25 SPAM = 1 # and this is the second comment
26 # ... and now a third!
27 STRING = "# This is not a comment."
28
29
30.. _tut-calculator:
31
32Using Python as a Calculator
33============================
34
35Let's try some simple Python commands. Start the interpreter and wait for the
36primary prompt, ``>>>``. (It shouldn't take long.)
37
38
39.. _tut-numbers:
40
41Numbers
42-------
43
44The interpreter acts as a simple calculator: you can type an expression at it
45and it will write the value. Expression syntax is straightforward: the
46operators ``+``, ``-``, ``*`` and ``/`` work just like in most other languages
47(for example, Pascal or C); parentheses can be used for grouping. For example::
48
49 >>> 2+2
50 4
51 >>> # This is a comment
52 ... 2+2
53 4
54 >>> 2+2 # and a comment on the same line as code
55 4
56 >>> (50-5*6)/4
Guido van Rossum0616b792007-08-31 03:25:11 +000057 5.0
58 >>> 8/5 # Fractions aren't lost when dividing integers
Mark Dickinsond1cc39d2009-06-28 21:00:42 +000059 1.6
Guido van Rossum0616b792007-08-31 03:25:11 +000060
Georg Brandl48310cd2009-01-03 21:18:54 +000061Note: You might not see exactly the same result; floating point results can
Guido van Rossum0616b792007-08-31 03:25:11 +000062differ from one machine to another. We will say more later about controlling
Mark Dickinson93078392009-06-28 21:20:21 +000063the appearance of floating point output. See also :ref:`tut-fp-issues` for a
64full discussion of some of the subtleties of floating point numbers and their
65representations.
Guido van Rossum0616b792007-08-31 03:25:11 +000066
Georg Brandl48310cd2009-01-03 21:18:54 +000067To do integer division and get an integer result,
Guido van Rossum0616b792007-08-31 03:25:11 +000068discarding any fractional result, there is another operator, ``//``::
Georg Brandl48310cd2009-01-03 21:18:54 +000069
Georg Brandl116aa622007-08-15 14:28:22 +000070 >>> # Integer division returns the floor:
Guido van Rossum0616b792007-08-31 03:25:11 +000071 ... 7//3
Georg Brandl116aa622007-08-15 14:28:22 +000072 2
Guido van Rossum0616b792007-08-31 03:25:11 +000073 >>> 7//-3
Georg Brandl116aa622007-08-15 14:28:22 +000074 -3
75
76The equal sign (``'='``) is used to assign a value to a variable. Afterwards, no
77result is displayed before the next interactive prompt::
78
79 >>> width = 20
80 >>> height = 5*9
81 >>> width * height
82 900
83
84A value can be assigned to several variables simultaneously::
85
86 >>> x = y = z = 0 # Zero x, y and z
87 >>> x
88 0
89 >>> y
90 0
91 >>> z
92 0
93
Georg Brandl5d955ed2008-09-13 17:18:21 +000094Variables must be "defined" (assigned a value) before they can be used, or an
95error will occur::
96
97 >>> # try to access an undefined variable
98 ... n
Georg Brandl48310cd2009-01-03 21:18:54 +000099 Traceback (most recent call last):
Georg Brandl5d955ed2008-09-13 17:18:21 +0000100 File "<stdin>", line 1, in <module>
101 NameError: name 'n' is not defined
102
Georg Brandl116aa622007-08-15 14:28:22 +0000103There is full support for floating point; operators with mixed type operands
104convert the integer operand to floating point::
105
106 >>> 3 * 3.75 / 1.5
107 7.5
108 >>> 7.0 / 2
109 3.5
110
111Complex numbers are also supported; imaginary numbers are written with a suffix
112of ``j`` or ``J``. Complex numbers with a nonzero real component are written as
113``(real+imagj)``, or can be created with the ``complex(real, imag)`` function.
114::
115
116 >>> 1j * 1J
117 (-1+0j)
Georg Brandle4ac7502007-09-03 07:10:24 +0000118 >>> 1j * complex(0, 1)
Georg Brandl116aa622007-08-15 14:28:22 +0000119 (-1+0j)
120 >>> 3+1j*3
121 (3+3j)
122 >>> (3+1j)*3
123 (9+3j)
124 >>> (1+2j)/(1+1j)
125 (1.5+0.5j)
126
127Complex numbers are always represented as two floating point numbers, the real
128and imaginary part. To extract these parts from a complex number *z*, use
129``z.real`` and ``z.imag``. ::
130
131 >>> a=1.5+0.5j
132 >>> a.real
133 1.5
134 >>> a.imag
135 0.5
136
137The conversion functions to floating point and integer (:func:`float`,
Georg Brandl2d2590d2007-09-28 13:13:35 +0000138:func:`int`) don't work for complex numbers --- there is not one correct way to
139convert a complex number to a real number. Use ``abs(z)`` to get its magnitude
140(as a float) or ``z.real`` to get its real part::
Georg Brandl116aa622007-08-15 14:28:22 +0000141
142 >>> a=3.0+4.0j
143 >>> float(a)
144 Traceback (most recent call last):
145 File "<stdin>", line 1, in ?
146 TypeError: can't convert complex to float; use abs(z)
147 >>> a.real
148 3.0
149 >>> a.imag
150 4.0
151 >>> abs(a) # sqrt(a.real**2 + a.imag**2)
152 5.0
153 >>>
154
155In interactive mode, the last printed expression is assigned to the variable
156``_``. This means that when you are using Python as a desk calculator, it is
157somewhat easier to continue calculations, for example::
158
159 >>> tax = 12.5 / 100
160 >>> price = 100.50
161 >>> price * tax
162 12.5625
163 >>> price + _
164 113.0625
165 >>> round(_, 2)
166 113.06
167 >>>
168
169This variable should be treated as read-only by the user. Don't explicitly
170assign a value to it --- you would create an independent local variable with the
171same name masking the built-in variable with its magic behavior.
172
173
174.. _tut-strings:
175
176Strings
177-------
178
179Besides numbers, Python can also manipulate strings, which can be expressed in
180several ways. They can be enclosed in single quotes or double quotes::
181
182 >>> 'spam eggs'
183 'spam eggs'
184 >>> 'doesn\'t'
185 "doesn't"
186 >>> "doesn't"
187 "doesn't"
188 >>> '"Yes," he said.'
189 '"Yes," he said.'
190 >>> "\"Yes,\" he said."
191 '"Yes," he said.'
192 >>> '"Isn\'t," she said.'
193 '"Isn\'t," she said.'
194
Guido van Rossum0616b792007-08-31 03:25:11 +0000195The interpreter prints the result of string operations in the same way as they
196are typed for input: inside quotes, and with quotes and other funny characters
197escaped by backslashes, to show the precise value. The string is enclosed in
198double quotes if the string contains a single quote and no double quotes, else
199it's enclosed in single quotes. Once again, the :func:`print` function
200produces the more readable output.
201
Georg Brandl116aa622007-08-15 14:28:22 +0000202String literals can span multiple lines in several ways. Continuation lines can
203be used, with a backslash as the last character on the line indicating that the
204next line is a logical continuation of the line::
205
206 hello = "This is a rather long string containing\n\
207 several lines of text just as you would do in C.\n\
208 Note that whitespace at the beginning of the line is\
209 significant."
210
Guido van Rossum0616b792007-08-31 03:25:11 +0000211 print(hello)
Georg Brandl116aa622007-08-15 14:28:22 +0000212
213Note that newlines still need to be embedded in the string using ``\n``; the
214newline following the trailing backslash is discarded. This example would print
215the following::
216
217 This is a rather long string containing
218 several lines of text just as you would do in C.
219 Note that whitespace at the beginning of the line is significant.
220
Benjamin Petersond23f8222009-04-05 19:13:16 +0000221If we make the string literal a "raw" string, ``\n`` sequences are not converted
222to newlines, but the backslash at the end of the line, and the newline character
223in the source, are both included in the string as data. Thus, the example::
Georg Brandl116aa622007-08-15 14:28:22 +0000224
225 hello = r"This is a rather long string containing\n\
226 several lines of text much as you would do in C."
227
Guido van Rossum0616b792007-08-31 03:25:11 +0000228 print(hello)
Georg Brandl116aa622007-08-15 14:28:22 +0000229
230would print::
231
232 This is a rather long string containing\n\
233 several lines of text much as you would do in C.
234
Georg Brandl116aa622007-08-15 14:28:22 +0000235Strings can be concatenated (glued together) with the ``+`` operator, and
236repeated with ``*``::
237
238 >>> word = 'Help' + 'A'
239 >>> word
240 'HelpA'
241 >>> '<' + word*5 + '>'
242 '<HelpAHelpAHelpAHelpAHelpA>'
243
244Two string literals next to each other are automatically concatenated; the first
245line above could also have been written ``word = 'Help' 'A'``; this only works
246with two literals, not with arbitrary string expressions::
247
248 >>> 'str' 'ing' # <- This is ok
249 'string'
250 >>> 'str'.strip() + 'ing' # <- This is ok
251 'string'
252 >>> 'str'.strip() 'ing' # <- This is invalid
253 File "<stdin>", line 1, in ?
254 'str'.strip() 'ing'
255 ^
256 SyntaxError: invalid syntax
257
258Strings can be subscripted (indexed); like in C, the first character of a string
259has subscript (index) 0. There is no separate character type; a character is
Georg Brandle4ac7502007-09-03 07:10:24 +0000260simply a string of size one. As in the Icon programming language, substrings
261can be specified with the *slice notation*: two indices separated by a colon.
262::
Georg Brandl116aa622007-08-15 14:28:22 +0000263
264 >>> word[4]
265 'A'
266 >>> word[0:2]
267 'He'
268 >>> word[2:4]
269 'lp'
270
271Slice indices have useful defaults; an omitted first index defaults to zero, an
272omitted second index defaults to the size of the string being sliced. ::
273
274 >>> word[:2] # The first two characters
275 'He'
276 >>> word[2:] # Everything except the first two characters
277 'lpA'
278
Georg Brandl5d955ed2008-09-13 17:18:21 +0000279Unlike a C string, Python strings cannot be changed. Assigning to an indexed
Georg Brandl116aa622007-08-15 14:28:22 +0000280position in the string results in an error::
281
282 >>> word[0] = 'x'
283 Traceback (most recent call last):
284 File "<stdin>", line 1, in ?
Georg Brandl7fcb3bf2009-05-17 08:18:02 +0000285 TypeError: 'str' object does not support item assignment
Georg Brandl116aa622007-08-15 14:28:22 +0000286 >>> word[:1] = 'Splat'
287 Traceback (most recent call last):
288 File "<stdin>", line 1, in ?
Georg Brandl7fcb3bf2009-05-17 08:18:02 +0000289 TypeError: 'str' object does not support slice assignment
Georg Brandl116aa622007-08-15 14:28:22 +0000290
291However, creating a new string with the combined content is easy and efficient::
292
293 >>> 'x' + word[1:]
294 'xelpA'
295 >>> 'Splat' + word[4]
296 'SplatA'
297
298Here's a useful invariant of slice operations: ``s[:i] + s[i:]`` equals ``s``.
299::
300
301 >>> word[:2] + word[2:]
302 'HelpA'
303 >>> word[:3] + word[3:]
304 'HelpA'
305
306Degenerate slice indices are handled gracefully: an index that is too large is
307replaced by the string size, an upper bound smaller than the lower bound returns
308an empty string. ::
309
310 >>> word[1:100]
311 'elpA'
312 >>> word[10:]
313 ''
314 >>> word[2:1]
315 ''
316
317Indices may be negative numbers, to start counting from the right. For example::
318
319 >>> word[-1] # The last character
320 'A'
321 >>> word[-2] # The last-but-one character
322 'p'
323 >>> word[-2:] # The last two characters
324 'pA'
325 >>> word[:-2] # Everything except the last two characters
326 'Hel'
327
328But note that -0 is really the same as 0, so it does not count from the right!
329::
330
331 >>> word[-0] # (since -0 equals 0)
332 'H'
333
334Out-of-range negative slice indices are truncated, but don't try this for
335single-element (non-slice) indices::
336
337 >>> word[-100:]
338 'HelpA'
339 >>> word[-10] # error
340 Traceback (most recent call last):
341 File "<stdin>", line 1, in ?
342 IndexError: string index out of range
343
344One way to remember how slices work is to think of the indices as pointing
345*between* characters, with the left edge of the first character numbered 0.
346Then the right edge of the last character of a string of *n* characters has
347index *n*, for example::
348
Georg Brandl48310cd2009-01-03 21:18:54 +0000349 +---+---+---+---+---+
Georg Brandl116aa622007-08-15 14:28:22 +0000350 | H | e | l | p | A |
Georg Brandl48310cd2009-01-03 21:18:54 +0000351 +---+---+---+---+---+
352 0 1 2 3 4 5
Georg Brandl116aa622007-08-15 14:28:22 +0000353 -5 -4 -3 -2 -1
354
355The first row of numbers gives the position of the indices 0...5 in the string;
356the second row gives the corresponding negative indices. The slice from *i* to
357*j* consists of all characters between the edges labeled *i* and *j*,
358respectively.
359
360For non-negative indices, the length of a slice is the difference of the
361indices, if both are within bounds. For example, the length of ``word[1:3]`` is
3622.
363
364The built-in function :func:`len` returns the length of a string::
365
366 >>> s = 'supercalifragilisticexpialidocious'
367 >>> len(s)
368 34
369
370
371.. seealso::
372
373 :ref:`typesseq`
Georg Brandl48310cd2009-01-03 21:18:54 +0000374 Strings are examples of *sequence types*, and support the common
Guido van Rossum0616b792007-08-31 03:25:11 +0000375 operations supported by such types.
Georg Brandl116aa622007-08-15 14:28:22 +0000376
377 :ref:`string-methods`
Guido van Rossum0616b792007-08-31 03:25:11 +0000378 Strings support a large number of methods for
Georg Brandl116aa622007-08-15 14:28:22 +0000379 basic transformations and searching.
380
381 :ref:`string-formatting`
Benjamin Petersone6f00632008-05-26 01:03:56 +0000382 Information about string formatting with :meth:`str.format` is described
383 here.
384
385 :ref:`old-string-formatting`
386 The old formatting operations invoked when strings and Unicode strings are
387 the left operand of the ``%`` operator are described in more detail here.
Georg Brandl116aa622007-08-15 14:28:22 +0000388
389
390.. _tut-unicodestrings:
391
Guido van Rossum0616b792007-08-31 03:25:11 +0000392About Unicode
393-------------
Georg Brandl116aa622007-08-15 14:28:22 +0000394
395.. sectionauthor:: Marc-Andre Lemburg <mal@lemburg.com>
396
397
Georg Brandl5d955ed2008-09-13 17:18:21 +0000398Starting with Python 3.0 all strings support Unicode (see
399http://www.unicode.org/).
Georg Brandl116aa622007-08-15 14:28:22 +0000400
401Unicode has the advantage of providing one ordinal for every character in every
402script used in modern and ancient texts. Previously, there were only 256
403possible ordinals for script characters. Texts were typically bound to a code
404page which mapped the ordinals to script characters. This lead to very much
405confusion especially with respect to internationalization (usually written as
406``i18n`` --- ``'i'`` + 18 characters + ``'n'``) of software. Unicode solves
407these problems by defining one code page for all scripts.
408
Guido van Rossum0616b792007-08-31 03:25:11 +0000409If you want to include special characters in a string,
Georg Brandl116aa622007-08-15 14:28:22 +0000410you can do so by using the Python *Unicode-Escape* encoding. The following
411example shows how::
412
Guido van Rossum0616b792007-08-31 03:25:11 +0000413 >>> 'Hello\u0020World !'
414 'Hello World !'
Georg Brandl116aa622007-08-15 14:28:22 +0000415
416The escape sequence ``\u0020`` indicates to insert the Unicode character with
417the ordinal value 0x0020 (the space character) at the given position.
418
419Other characters are interpreted by using their respective ordinal values
420directly as Unicode ordinals. If you have literal strings in the standard
421Latin-1 encoding that is used in many Western countries, you will find it
422convenient that the lower 256 characters of Unicode are the same as the 256
423characters of Latin-1.
424
Georg Brandl116aa622007-08-15 14:28:22 +0000425Apart from these standard encodings, Python provides a whole set of other ways
426of creating Unicode strings on the basis of a known encoding.
427
Guido van Rossum0616b792007-08-31 03:25:11 +0000428To convert a string into a sequence of bytes using a specific encoding,
429string objects provide an :func:`encode` method that takes one argument, the
Georg Brandl116aa622007-08-15 14:28:22 +0000430name of the encoding. Lowercase names for encodings are preferred. ::
431
Georg Brandlc3f5bad2007-08-31 06:46:05 +0000432 >>> "Äpfel".encode('utf-8')
433 b'\xc3\x84pfel'
Georg Brandl116aa622007-08-15 14:28:22 +0000434
435.. _tut-lists:
436
437Lists
438-----
439
440Python knows a number of *compound* data types, used to group together other
441values. The most versatile is the *list*, which can be written as a list of
442comma-separated values (items) between square brackets. List items need not all
443have the same type. ::
444
445 >>> a = ['spam', 'eggs', 100, 1234]
446 >>> a
447 ['spam', 'eggs', 100, 1234]
448
449Like string indices, list indices start at 0, and lists can be sliced,
450concatenated and so on::
451
452 >>> a[0]
453 'spam'
454 >>> a[3]
455 1234
456 >>> a[-2]
457 100
458 >>> a[1:-1]
459 ['eggs', 100]
460 >>> a[:2] + ['bacon', 2*2]
461 ['spam', 'eggs', 'bacon', 4]
462 >>> 3*a[:3] + ['Boo!']
463 ['spam', 'eggs', 100, 'spam', 'eggs', 100, 'spam', 'eggs', 100, 'Boo!']
464
465Unlike strings, which are *immutable*, it is possible to change individual
466elements of a list::
467
468 >>> a
469 ['spam', 'eggs', 100, 1234]
470 >>> a[2] = a[2] + 23
471 >>> a
472 ['spam', 'eggs', 123, 1234]
473
474Assignment to slices is also possible, and this can even change the size of the
475list or clear it entirely::
476
477 >>> # Replace some items:
478 ... a[0:2] = [1, 12]
479 >>> a
480 [1, 12, 123, 1234]
481 >>> # Remove some:
482 ... a[0:2] = []
483 >>> a
484 [123, 1234]
485 >>> # Insert some:
486 ... a[1:1] = ['bletch', 'xyzzy']
487 >>> a
488 [123, 'bletch', 'xyzzy', 1234]
489 >>> # Insert (a copy of) itself at the beginning
490 >>> a[:0] = a
491 >>> a
492 [123, 'bletch', 'xyzzy', 1234, 123, 'bletch', 'xyzzy', 1234]
493 >>> # Clear the list: replace all items with an empty list
494 >>> a[:] = []
495 >>> a
496 []
497
498The built-in function :func:`len` also applies to lists::
499
Guido van Rossum58da9312007-11-10 23:39:45 +0000500 >>> a = ['a', 'b', 'c', 'd']
Georg Brandl116aa622007-08-15 14:28:22 +0000501 >>> len(a)
Guido van Rossum58da9312007-11-10 23:39:45 +0000502 4
Georg Brandl116aa622007-08-15 14:28:22 +0000503
504It is possible to nest lists (create lists containing other lists), for
505example::
506
507 >>> q = [2, 3]
508 >>> p = [1, q, 4]
509 >>> len(p)
510 3
511 >>> p[1]
512 [2, 3]
513 >>> p[1][0]
514 2
Guido van Rossum0616b792007-08-31 03:25:11 +0000515
516You can add something to the end of the list::
517
Georg Brandle4ac7502007-09-03 07:10:24 +0000518 >>> p[1].append('xtra')
Georg Brandl116aa622007-08-15 14:28:22 +0000519 >>> p
520 [1, [2, 3, 'xtra'], 4]
521 >>> q
522 [2, 3, 'xtra']
523
524Note that in the last example, ``p[1]`` and ``q`` really refer to the same
525object! We'll come back to *object semantics* later.
526
527
528.. _tut-firststeps:
529
530First Steps Towards Programming
531===============================
532
533Of course, we can use Python for more complicated tasks than adding two and two
534together. For instance, we can write an initial sub-sequence of the *Fibonacci*
535series as follows::
536
537 >>> # Fibonacci series:
538 ... # the sum of two elements defines the next
539 ... a, b = 0, 1
540 >>> while b < 10:
Georg Brandl22ec03c2008-01-07 17:32:13 +0000541 ... print(b)
542 ... a, b = b, a+b
Georg Brandl48310cd2009-01-03 21:18:54 +0000543 ...
Georg Brandl116aa622007-08-15 14:28:22 +0000544 1
545 1
546 2
547 3
548 5
549 8
550
551This example introduces several new features.
552
553* The first line contains a *multiple assignment*: the variables ``a`` and ``b``
554 simultaneously get the new values 0 and 1. On the last line this is used again,
555 demonstrating that the expressions on the right-hand side are all evaluated
556 first before any of the assignments take place. The right-hand side expressions
557 are evaluated from the left to the right.
558
559* The :keyword:`while` loop executes as long as the condition (here: ``b < 10``)
560 remains true. In Python, like in C, any non-zero integer value is true; zero is
561 false. The condition may also be a string or list value, in fact any sequence;
562 anything with a non-zero length is true, empty sequences are false. The test
563 used in the example is a simple comparison. The standard comparison operators
564 are written the same as in C: ``<`` (less than), ``>`` (greater than), ``==``
565 (equal to), ``<=`` (less than or equal to), ``>=`` (greater than or equal to)
566 and ``!=`` (not equal to).
567
568* The *body* of the loop is *indented*: indentation is Python's way of grouping
569 statements. Python does not (yet!) provide an intelligent input line editing
570 facility, so you have to type a tab or space(s) for each indented line. In
571 practice you will prepare more complicated input for Python with a text editor;
572 most text editors have an auto-indent facility. When a compound statement is
573 entered interactively, it must be followed by a blank line to indicate
574 completion (since the parser cannot guess when you have typed the last line).
575 Note that each line within a basic block must be indented by the same amount.
576
Guido van Rossum0616b792007-08-31 03:25:11 +0000577* The :func:`print` function writes the value of the expression(s) it is
Georg Brandl116aa622007-08-15 14:28:22 +0000578 given. It differs from just writing the expression you want to write (as we did
Georg Brandl48310cd2009-01-03 21:18:54 +0000579 earlier in the calculator examples) in the way it handles multiple
580 expressions, floating point quantities,
Georg Brandl116aa622007-08-15 14:28:22 +0000581 and strings. Strings are printed without quotes, and a space is inserted
582 between items, so you can format things nicely, like this::
583
584 >>> i = 256*256
Guido van Rossum0616b792007-08-31 03:25:11 +0000585 >>> print('The value of i is', i)
Georg Brandl116aa622007-08-15 14:28:22 +0000586 The value of i is 65536
587
Georg Brandl11e18b02008-08-05 09:04:16 +0000588 The keyword *end* can be used to avoid the newline after the output, or end
589 the output with a different string::
Georg Brandl116aa622007-08-15 14:28:22 +0000590
591 >>> a, b = 0, 1
592 >>> while b < 1000:
Georg Brandl11e18b02008-08-05 09:04:16 +0000593 ... print(b, end=' ')
Georg Brandl116aa622007-08-15 14:28:22 +0000594 ... a, b = b, a+b
Georg Brandl48310cd2009-01-03 21:18:54 +0000595 ...
Georg Brandl116aa622007-08-15 14:28:22 +0000596 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987