Python & Perl: Lecture 01

1,731 views
1,664 views

Published on

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,731
On SlideShare
0
From Embeds
0
Number of Embeds
528
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Python & Perl: Lecture 01

  1. 1. Python & Perl Lecture 01 Vladimir Kulyukin Department of Computer Science Utah State Universitywww.youtube.com/vkedco www.vkedco.blogspot.com
  2. 2. Outline ● Course Overview ● Python Overview: History, Features, Strengths, Weaknesses ● Installing Python on Windows/Linux/Mac OS ● Python 2.X or Python 3.X ● Playing with Python through its Interpreter ● Comments, Booleans, Variables, Lists, Strings, Tuples ● Built-in Functions and Methodswww.youtube.com/vkedco www.vkedco.blogspot.com
  3. 3. Previous Student Feedbackwww.youtube.com/vkedco www.vkedco.blogspot.com
  4. 4. Student Quote 01 I really enjoyed this course. The best thing about it is that it has two languages. The worst thing about it is that it has two languages. When I was ready to do more challenging programming in Python, we switched to Perl. In the end, while I did get a great introduction to both Python and Perl, I wish I had a chance to work on a larger Python project.www.youtube.com/vkedco www.vkedco.blogspot.com
  5. 5. Student Quote 02 Nice class, but ditch Perl and focus only on Python next time you teach it. Python is a lot more functional and easier to deal with than Perl.www.youtube.com/vkedco www.vkedco.blogspot.com
  6. 6. Student Quote 03 I wanted to see more Perl than Python.www.youtube.com/vkedco www.vkedco.blogspot.com
  7. 7. Schedule & Workload ● Python – 10 weeks ● Perl – 5 weeks ● Two exams (dates in the syllabus) – Midterm: Python – Final: Python & Perl (mostly Perl) ● Small in-class quizzes (worth 0 points) ● Regular weekly/bi-weekly coding assignments ● Final project (last 4 weeks)www.youtube.com/vkedco www.vkedco.blogspot.com
  8. 8. Textswww.youtube.com/vkedco www.vkedco.blogspot.com
  9. 9. Python Text 1www.youtube.com/vkedco www.vkedco.blogspot.com
  10. 10. Python Text 2 Download free PDF version at http://greenteapress.com/thinkpython/thinkpython.htmlwww.youtube.com/vkedco www.vkedco.blogspot.com
  11. 11. Perl Textwww.youtube.com/vkedco www.vkedco.blogspot.com
  12. 12. Class Home Page ● Go to my page at the USU CS Department or google/bing/yahoo “vladimir kulyukin” ● Click on “Teaching” ● Click on “CS3430: Python & Perl” ● Read the syllabuswww.youtube.com/vkedco www.vkedco.blogspot.com
  13. 13. Logistics ● We will use Dropbox for assignments, projects, and exams ● If you do not have Dropbox installed, spend two minutes on installing it and send me an email with your first and last name (details are in the syllabus) ● Both exams will be online; you can take them anywhere you want ● Do not send any email to my Canvas/Blackboard accounts; use my email given in the syllabus ● Turn off your cell phones in classwww.youtube.com/vkedco www.vkedco.blogspot.com
  14. 14. Class Attendance ● Class attendance is completely optional ● I know students who show up for every class and get Cs and Ds; I know students who show up for no class or just a few classes and ace all assignments, projects, and exams ● Do not waste your time showing up for class to do homework for other classes, read email, browse the web, chat with friends, play games, etcwww.youtube.com/vkedco www.vkedco.blogspot.com
  15. 15. Python Overview History, Features, Strengths, Weaknesseswww.youtube.com/vkedco www.vkedco.blogspot.com
  16. 16. History ● Python is a general purpose programming language ● Python is considered a scripting language but it is pos- sible and practical to develop systems and executables ● Python was created by Guido van Rossum in the 1990s. ● Guido van Rossum is sometimes referred to as “Pythons Benevolent Dictator for Life” (BDFL). ● The name “Python” comes from “Monty Pythons Flying Circus.”www.youtube.com/vkedco www.vkedco.blogspot.com
  17. 17. Features ● Dynamic typing ● Automatic memory management (aka garbage collection) ● Support for large applications (system programming) ● Numerous built-in tools and libraries ● Numerous 3rd party tools and librarieswww.youtube.com/vkedco www.vkedco.blogspot.com
  18. 18. Strengths ● Free ● Portable ● Easy to learn and use ● Mixable –C/C++ programs can call Python programs – Python can link to C/C++ libraries ● Supports object-oriented programmingwww.youtube.com/vkedco www.vkedco.blogspot.com
  19. 19. Weakness ● Python programs can run more slowly than their C/C++ counterparts ● If and when this happens, you have to ask yourselves two questions: – Do I really need this for my particular application? In many cases, no! – Can I port the bottleneck to C/C++? In many cases, yes!www.youtube.com/vkedco www.vkedco.blogspot.com
  20. 20. Why not C++ for Everything? Scripting languages represent a different set of tradeoffs than system programming languages. They give up execution speed and strength of typing relative to system programming languages but provide significantly higher programmer productivity and software reuse. John K. Ousterhout, Creator of Tcl “Scripting: Higher Level Programming for the 21st Century” IEEE Computer magazine, March 1998 Full article: http://www.tcl.tk/doc/scripting.htmlwww.youtube.com/vkedco www.vkedco.blogspot.com
  21. 21. Python 2.X or Python 3.Xwww.youtube.com/vkedco www.vkedco.blogspot.com
  22. 22. Python 2 or Python 3? ● Python 2.X is the status quo, Python 3.x is the shiny new thing ● Python 3.X is the newest branch of Python and the intended future of the language ● However, the broader Python ecosystem has amassed a significant amount of quality software over the years ● Insightful article on Python 2 vs. Python 3 on www.python.orgwww.youtube.com/vkedco www.vkedco.blogspot.com
  23. 23. Python 2 or Python 3? ● While Python 3.X is the same language, it is not backward compatible to Python 2.X ● The downside of breaking backwards compatibility in 3.X is that a lot of that software does not work on 3.X yet; this transition will take time ● Python 3.X has relatively limited library support; many Linux distributions and Macs ship with 2.Xwww.youtube.com/vkedco www.vkedco.blogspot.com
  24. 24. Reasons to Prefer Python 2 over Python 3 (For Now) 1. If you are deploying to an environment you do not control. 2. If you use a third party package that does not have a released Python 3 version. 3. If you want to use a third-party tool such as Python Image Library (PIL), Twisted (for networking), Django (for building websites), or py2exe (for packaging your application for Windows users)www.youtube.com/vkedco www.vkedco.blogspot.com
  25. 25. Reasons to Prefer Python 2 over Python 3 (For Now) 4. A lot of documentation (including examples) on the web and in reference books will be for Python 2 for the near future 5. Most of us are inclined to seek help online. The Python regulars are typically seasoned developers who rely on legacy software, most of which has not been ported to Python 3 yet. As a result, they might not be able to help you with Python issues 6. It is always better to study the tool you are transitioning to and wait until it becomes accepted by the broader community.www.youtube.com/vkedco www.vkedco.blogspot.com
  26. 26. Q&A from www.python.org Question: But wouldnt I want to avoid 2.x? Its an old language with a bunch of mistakes, and it took a major version to get em out? Answer: Well, not really. The good news is that you dont have to drop all of the 3.x goodness because youre using 2.x. A lot of the good ideas in 3.0 were backported to 2.6, and even more of the good ideas from 3.0, 3.1 and the upcoming 3.2 will be available in 2.7. The number of things that you really cant do in 2.x but can in 3.x is pretty small: its just not always as elegant as it is in 3.x.www.youtube.com/vkedco www.vkedco.blogspot.com
  27. 27. Installing Python on Windows/Linux/Mac OSwww.youtube.com/vkedco www.vkedco.blogspot.com
  28. 28. What We Will Use ● We will use Python 2.7 in this class ● If you are a Linux user, note that many versions of Linux ship with 2.6.X ● If you are a Mac user, note that most Macs still ship with 2.6.X; check for the Mac distribution of 2.7www.youtube.com/vkedco www.vkedco.blogspot.com
  29. 29. Installing Python ● www.python.org is the site for everything that is Python. ● On Windows, I use IDLE for execution and debugging and IDLE or Emacs for editing ● On Linux (Ubuntu), I use command line interpreters for execution and debugging and Emacs for editing. ● You may want to play with several choices and choose what you like best. It does not really matter which IDE you use. You will submit only the Python source files (.py) in your assignmentswww.youtube.com/vkedco www.vkedco.blogspot.com
  30. 30. Playing with Pythonwww.youtube.com/vkedco www.vkedco.blogspot.com
  31. 31. Python Interpreter ● Python Interpreter is an interactive program that allows you to work with Python source code without having to create, edit, save, and compile source files ● As you read online materials or test, I suggest that you keep the Python interpreter window running and try code snippets right away ● Most Python IDEs make the Python interpreter easily availablewww.youtube.com/vkedco www.vkedco.blogspot.com
  32. 32. Python Interpreter >>> print Hello, Python! Hello, Python! >>> “Hello, Python!” Hello, Python! >>> 5 5 >>> 5 + 10 15www.youtube.com/vkedco www.vkedco.blogspot.com
  33. 33. Comments ● The hash mark character (#) introduces comments ● # can appear at the beginning of a line or in the middle of a line ● The characters after # and upto n are part of a comment ● Examples: – # This is a comment – x + y # add x and ywww.youtube.com/vkedco www.vkedco.blogspot.com
  34. 34. Variables ● Since Python is a dynamically typed language, the types of variables are not explicitly declared ● A variable can refer to an object of any legal Python type ● The type of a variable is determined at run time through the operations that are applied to the variables value ● Examples: – >>> x = 1 # the value of x is integer 1 – >>> x + 1 # is OK – >>> x + bar # is ERROR –www.youtube.com/vkedco www.vkedco.blogspot.com
  35. 35. Booleans ● Python has two Boolean values: True and False ● All Python values can be represented as Booleans: all numbers except 0 are True; all non-empty containers are True; all empty containers are False; For example: – >>> file_ready = False – >>> bool(file_ready) False – >>> bool(1) True – >>> bool([]) – Falsewww.youtube.com/vkedco www.vkedco.blogspot.com
  36. 36. Factory Functions ● Numeric types have factory functions that convert from one type to another; For example: – >>> int(12) 12 – >>> int(12.5) 12 – >>> int(12.1) ERROR – >>> float(12.1) 12.1www.youtube.com/vkedco www.vkedco.blogspot.com
  37. 37. Lists, Strings, Tuples, Iterables ● Lists: [1, 2, a] ● Strings: Python, “Python”, “Djangon” ● Tuples: (a, 1), (1, 2) ● Lists are mutable (support assignment) ● Strings and tuples are immutable ● Iterables are any objects that can be iterated through one item at a timewww.youtube.com/vkedco www.vkedco.blogspot.com
  38. 38. Reading & References ● www.python.org. ● Ch. 01, M. L. HetLand. Beginning Python From Novice to nd Professional, ,2 Ed., APRESS. ● H. Abelson and J. Sussman. Structure and Interpretation of Computer Programs, 2nd Ed., MIT Press.www.youtube.com/vkedco www.vkedco.blogspot.com
  39. 39. Feedback Errors, bugs, comments to vladimir dot kulyukin at usu dot eduwww.youtube.com/vkedco www.vkedco.blogspot.com

×