You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -374,25 +376,16 @@ For this course, I've suggested your company set up the following tools:
374
376
.. class:: incremental
375
377
376
378
* **Python 2.7**: the latest "stable/prod" version of Python
377
-
* **Console2**: a better console for Windows
378
-
* **Cream**: an easy-to-use extension of the ViM text editor
379
-
* **WingIDE 101**: a full-fledged Python IDE
380
379
* **IPython**: an interactive Python shell
380
+
* **pip**: python's package manager
381
+
* **IPython Notebook**: a browser-based Python REPL and interactive environment
381
382
382
-
Quick note on WingIDE
383
-
---------------------
384
-
385
-
.. image:: img/02_ide.png
386
-
:class:scaled
387
-
388
-
Python, IPython, BPython, DreamPie
389
-
----------------------------------
383
+
Python, IPython, IPython Notebook
384
+
---------------------------------
390
385
391
386
One of Python's best features is the REPL loop, or **Read**, **Evaluate**, **Print** **Loop**.
392
387
393
-
Open source developers have created a number of "enhanced" REPLs over the years. The most common of these is **IPython**, but there is also **BPython** and **DreamPie**.
394
-
395
-
WingIDE has its own REPL that is integrated with the IDE and works in debug mode, as well.
388
+
Open source developers have created a number of "enhanced" REPLs over the years. The most common of these is **IPython Notebook**, but there is also regular old **IPython** as well as others.
396
389
397
390
BREAK: Confirm system settings
398
391
------------------------------
@@ -479,7 +472,7 @@ Minimal automatic coercion
479
472
480
473
>>> string ="two"
481
474
>>> number =3
482
-
>>> string, integer=integer, string # swap values
475
+
>>> string, number=number, string # swap values
483
476
>>> print string + number
484
477
Traceback (most recent call last)
485
478
string + number
@@ -512,7 +505,7 @@ Why indentation?
512
505
513
506
Better answer: because some of us don't.
514
507
515
-
`Python Style Guide (PEP 8)`_ recommends 4 spaces, and no tab characters.
508
+
`Python Style Guide (PEP 8)`_ specifies 4 spaces, and no tab characters.
if __name__ == "__main__": # only runs when script is executed
623
+
"""This comment can span multiple
624
+
lines
625
+
"""
630
626
print "Hello, World"
631
627
632
628
Math and Numbers
@@ -674,32 +670,27 @@ When dealing with non-scientific computations, you probably want to use the ``De
674
670
675
671
To make it a little easier to use, I imported it using a module alias ``D``.
676
672
677
-
Fractions
678
-
---------
679
-
680
-
.. sourcecode:: python
681
-
682
-
>>> from fractions import Fraction as F
683
-
>>> F(1, 3) + F(1, 2)
684
-
Fraction(5, 6)
685
-
686
673
Formatting
687
674
----------
688
675
689
-
There are two simple ways to do string formatting in Python, and both are very popular.
676
+
There are a few ways to do string formatting in Python, though one is preferred.
677
+
``str.format`` is a method on ``str`` that provides a full complement of
678
+
string formatting features.
690
679
691
-
* ``%``, defined on ``str`` objects.
692
-
* ``str.format``, a more verbose method available on ``str``.
680
+
.. sourcecode:: python
681
+
682
+
>>> "{num} cars crossed the intersection \
683
+
in the last {hrs} hours".format(num=5, hrs=24)
684
+
5 cars crossed the intersection in the last 24 hours
693
685
686
+
``%``, defined on ``str`` objects, is sometimes used in older code for basic
687
+
string formatting.
694
688
695
689
.. sourcecode:: python
696
690
697
691
>>> "%s cars crossed the intersection \
698
692
in the last %s hours" % (5, 24)
699
693
5 cars crossed the intersection in the last 24 hours
700
-
>>> "{num} cars crossed the intersection \
701
-
in the last {hrs} hours".format(num=5, hrs=24)
702
-
5 cars crossed the intersection in the last 24 hours
703
694
704
695
705
696
Strings
@@ -928,6 +919,7 @@ Using an elif chain
928
919
else:
929
920
return None
930
921
922
+
931
923
Lists
932
924
-----
933
925
@@ -971,15 +963,21 @@ Lists can be concatenated with other lists using ``extend``, which creates a new
971
963
List slicing
972
964
------------
973
965
974
-
Lists have a convenient syntax for accessing single elements or even ranges of elements. This is called *slicing* and can also be done with the ``slice`` builtin function or ``[i:j:stride]`` syntax.
966
+
Lists (and other "sequences") have a convenient syntax for accessing single elements or even ranges of elements. This is called *slicing* and can also be done with the ``slice`` builtin function or ``[i:j:step]`` syntax.
975
967
976
968
.. image:: img/10_listslice.png
977
969
:align:center
978
970
971
+
.. sourcecode:: python
972
+
973
+
record = '....................100 .......513.25 ..........'
974
+
cost = int(record[20:32]) * float(record[40:48])
975
+
976
+
979
977
List aliasing
980
978
-------------
981
979
982
-
Lists can be aliased simply by binding a new label to the list. This sometimes leads to bugs!
980
+
Lists and other so-called "mutable objects" can be aliased simply by binding a new label to the list. This sometimes leads to bugs!
983
981
984
982
.. image:: img/11_listalias.png
985
983
:align:center
@@ -1028,18 +1026,17 @@ Switch statement to dictionary
0 commit comments