COSC 2P91
Introduction to Python Week 7a
Brock University
Brock University (Week 7a) Introduction to Python 1 / 20
COSC 2P91 Introduction to Python Week 7a Brock University Brock - - PowerPoint PPT Presentation
COSC 2P91 Introduction to Python Week 7a Brock University Brock University (Week 7a) Introduction to Python 1 / 20 Python Pythoff. Python. Pythoff. Python is a somewhat more modern language than C. It isnt quite as constrained by its
Brock University (Week 7a) Introduction to Python 1 / 20
Brock University (Week 7a) Introduction to Python 2 / 20
◮ Python 4 isn’t really officially released yet, so no worries there ◮ sandcastle has 2.6.6, but what matters is that it isn’t 3 ◮ Quite a few things changed with Python 3 ⋆ Python 3 is... not backwards-compatible with Python 2 ⋆ A migration tool is recommended to transition Python 2 code to 3 ⋆ Would you feel like rewriting all of your code (especially for a larger
⋆ Python 3 has a remarkably small market share, particularly on web
◮ For this course, we’ll be using Python 2 ⋆ Specifically, 2.6.6, but if you use a different version of Python 2 on your
Brock University (Week 7a) Introduction to Python 3 / 20
◮ You have a python script ◮ You tell Python to run that script ◮ Python runs that script ◮ You rejoice in the having-run-script-ness
◮ If you run Python without specifying a script, you get an interactive
◮ Compare to the REPL for Lisp
Brock University (Week 7a) Introduction to Python 4 / 20
◮ (Or that variables are effectively directly bound to values, but let’s not
Brock University (Week 7a) Introduction to Python 5 / 20
Brock University (Week 7a) Introduction to Python 6 / 20
◮ For this reason, they’re sometimes used as a multi-line comment ◮ Be careful doing this, because it’s normally for a specific purpose Brock University (Week 7a) Introduction to Python 7 / 20
Brock University (Week 7a) Introduction to Python 8 / 20
◮ The only thing to really look out for is that it expects strings for both
⋆ Consider the implications of this ⋆ Explicit conversion may be necessary at times
Brock University (Week 7a) Introduction to Python 9 / 20
◮ Perhaps we should look at lists of lists for a moment?
Brock University (Week 7a) Introduction to Python 10 / 20
Brock University (Week 7a) Introduction to Python 11 / 20
Brock University (Week 7a) Introduction to Python 12 / 20
◮ Compare [1,2]==[1,2] vs [1,2] is [1,2]
Brock University (Week 7a) Introduction to Python 13 / 20
◮ You can write it as a function, or treat it like a prefix operator ◮ print assumes one-line-per-print. Append a comma if you don’t want
◮ Use raw input instead! Brock University (Week 7a) Introduction to Python 14 / 20
Brock University (Week 7a) Introduction to Python 15 / 20
Brock University (Week 7a) Introduction to Python 16 / 20
Brock University (Week 7a) Introduction to Python 17 / 20
◮ Do we want to look at an example? Brock University (Week 7a) Introduction to Python 18 / 20
Brock University (Week 7a) Introduction to Python 19 / 20
Brock University (Week 7a) Introduction to Python 20 / 20