week 1- learn python 3 control flow

PatternCount("ACTAT", "ACAACTATGCATACTATCGGGAACTATCCT") = 3.

计算某个序列出现的次数,Note that PatternCount("ATA", "CGATATATCCATAG") is equal to 3 (not 2) since we should account for overlapping occurrences of Pattern in Text.

Go With the Flow

Control flow gives us this ability to choose among outcomes based on what else is happening in the program.

comparators

 Equal to (==)

 Not equal to (!=)

 Less than (<)

 Less than or equal to (<=)

 Greater than (>)

 Greater than or equal to (>=)

extreme expressions and comparators

How the Tables Have Turned

To Be and/or Not to Be

and, which checks if both the statements are True;

or, which checks if at least one of the statements is True;

not, which gives the opposite of the statement.


boolean operators


This and That (or This, But Not That!)

not is evaluated first;

and is evaluated next;

or is evaluated last.

Conditional Statement Syntax

    statement

if 8 < 9:

  print "Eight is less than nine!"

Pay attention to the indentation before the print statement. This space, called white space, is how Python knows we are entering a new block of code.此处用的是四个空格

If the indentation from one line to the next is different and there is no command (like if) that indicates an incoming block then Python will raise an IndentationError.

Python tries to indicate where this error happened by printing the line of code it couldn’t parse and using a ^ to point to where the indentation was different from what it expected.

if some_function():

  # block line one

  # block line two

  # et cetera

make sure you notice the colons at the end of the if statement

Else Problems, I Feel Bad for You, Son...

if 8 > 9:

  print "I don't get printed!"

else:

  print "I get printed!"

I Got 99 Problems, But a Switch Ain't One

if 8 > 9:

  print "I don't get printed!"

elif 8 < 9:

  print "I get printed!"

else:

  print "I also don't get printed!"

else if 语句



















d

你可能感兴趣的:(week 1- learn python 3 control flow)