Presentation is loading. Please wait.

Presentation is loading. Please wait.

Control Statements 1. Conditionals 2 Loops 3 4 Simple Loop Examples def echo(): while echo1(): pass def echo1(): line = input('Say something: ') print('You.

Similar presentations


Presentation on theme: "Control Statements 1. Conditionals 2 Loops 3 4 Simple Loop Examples def echo(): while echo1(): pass def echo1(): line = input('Say something: ') print('You."— Presentation transcript:

1 Control Statements 1

2 Conditionals 2

3 Loops 3

4 4 Simple Loop Examples def echo(): while echo1(): pass def echo1(): line = input('Say something: ') print('You said', line) return line def polite_echo(): while echo1() != 'bye': pass

5 Initialization of Loop Values 5

6 6 def recording_echo(): # initialize entry and lst vlst = [] # get the first input entry = echo1() # test entry while entry != 'bye': # use entry lst.append(entry) # change entry entry = echo1() # repeat # return result return lst

7 Looping Forever 7

8 Loops with Guard Conditions 8

9 Iterations Iteration Statements –Iteration statements all begin with the keyword for 9

10 Exception Handlers def get_gi_ids(filename): with open(filename) as file: return [extract_gi_id(line) for line in file if line[0] == '>'] IOError: [Errno 2] No such file or directory: 'aa2.fasta‘ 10

11 Python Errors –Tracebacks –Runtime errors 11

12 Exception Handling Statements 12

13 Classes 13

14 GeneBank Function 14

15 Problems of GeneBank Function Complexity –Using the representation in a program requires understanding its intricacies. Awkward navigation –Accessing specific parts of the representation requires tricky combinations of index expressions and function calls. Exposure to change –Changes to the representation require widespread changes in every program that uses it. 15

16 Defining Classes Python’s collection types work as follows: 1.The type is called like a function to create new instances. 2.The call to the type can include arguments used to initialize the new instance. 3.Methods are invoked on instances of types instead of accessing their internal representations. 4.Methods defined for different types can have the same name: when a method is called through a value, Python finds the appropriate function by looking in the definition of the value’s type. 5.The way an instance is printed is based on its type. 16

17 Defining Classes obj.name() obj.species 17

18 Example 18

19 Instance Attributes Access methods 19

20 Instance Attributes Predicate methods 20

21 Instance Attributes Initialization methodsString methods 21

22 Instance Attributes Modification methods Action methods 22 Support methods


Download ppt "Control Statements 1. Conditionals 2 Loops 3 4 Simple Loop Examples def echo(): while echo1(): pass def echo1(): line = input('Say something: ') print('You."

Similar presentations


Ads by Google