slides3-4up[1] - Compsci 6/101: PFTW APTs, Assignments,...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Compsci 06/101, Spring 2011 3.1 Compsci 6/101: PFTW APTs, Assignments, Tools What, How, When, Why How to get help and when to get it Review types and operations on types Names and types: int, float, long, string , file, list,… Operations: *, +, -, /, %, ** [:] Functions: organizing code (and ideas) Functions, modules, indentation, naming Parameterization to generalize solutions Return values to caller of function Compsci 06/101, Spring 2011 3.2 Functions: abstractions over code Naming something gives you power How do you find absolute value? What is length of a string? We can write and call functions Re-use and/or modify Store in module, import and re-use functions Import standard modules and use functions from them Functions can (should?) return a value We've seen len return an int, what about Other functions return Strings, floats, or other types Compsci 06/101, Spring 2011 3.3 Re-use: Counting words in file def wordCount(filename): file = open(filename) str = words = str.split() return len(words) name = "/data/romeo.txt" print "# words in",name, print "=",wordCount(filename) Compsci 06/101, Spring 2011 3.4 Anatomy of a Python function def name(params): body Define a function, provide a name, provide
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/17/2012 for the course COMPSCI 6 taught by Professor Duvall during the Spring '08 term at Duke.

Page1 / 3

slides3-4up[1] - Compsci 6/101: PFTW APTs, Assignments,...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online