









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The benefits of learning to program, with a focus on python as an accessible and relevant language for both computer science majors and non-majors. It covers the basics of python, including its ease of use, relevance to various fields, and the intellectual rewards of programming. The document also provides an overview of a university course on python programming.
Typology: Slides
1 / 16
This page cannot be seen from the preview
Don't miss anything!










(which is subtly distinct from, although a core part of, computer science itself) 3 From the Economist: “Teach computing, not Word” http://www.economist.com/blogs/babbage/2010/08/computing_schools Like philosophy, computing qua computing is worth teaching less for the subject matter itself and more for the habits of mind that studying it encourages. The best way to encourage interest in computing in school is to ditch the vocational stuff that strangles the subject currently, give the kids a simple programming language, and then get out of the way and let them experiment. For some, at least, it could be the start of a life-long love affair.
4 That, for me, sums up the seductive intellectual core of computers and computer programming: here is a magic black box. You can tell it to do whatever you want, within a certain set of rules, and it will do it; within the confines of the box you are more or less God, your powers limited only by your imagination. But the price of that power is strict discipline: you have to really know what you want, and you have to be able to express it clearly in a formal, structured way that leaves no room for the fuzzy thinking and ambiguity found everywhere else in life… The sense of freedom on offer - the ability to make the machine dance to any tune you care to play - is thrilling.
1/21/13 Overview; Types & Expressions 12
1/21/13 Overview; Types & Expressions 15
42 “Hello!” int eger
float (real number) str ing (of characters) 34 * (23 + 14) "Hel" + "lo!" 1.0 / 3.
§ Python evaluates it § End result is a value
§ Python executes it § Need not result in a value
§ print "Hello" § import sys 1/21/13 Overview; Types & Expressions 17 Literal An expression with four literals and some operators
Type: int
§ Integer mantissa times a power of 2 § Example: 1.25 is 10 * 2
§ Similar to problem of writing 1/3 with decimals § Python chooses the closest binary fraction it can
§ When combined in expressions, the error can get worse § Example : type 0.1 + 0.2 at the prompt >>> 1/21/13 Overview; Types & Expressions 20 mantissa exponent
Type: str
1/21/13 Overview; Types & Expressions 21
§ Example : 1/2.0 evaluates to 0.5 (casts 1 to float )
§ Narrowing conversions cause information to be lost § Example : float(int(2.6)) evaluates to 2. 1/21/13 Overview; Types & Expressions 23