• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/11

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

11 Cards in this Set

  • Front
  • Back
what are the rules for using list comprehensions?
Okay to use for simple cases. Each portion must fit on one line: mapping expression, for clause, filter expression. Multiple for clauses or filter expressions are not permitted. Use loops instead when things get more complicated.
how do you check if a key is not in a dictionary?
[key-name] not in [dictionary-name]
how do you iterate through the key value pairs in a dictionary?
for k,v in [dictionary name].iteritems():
what is the proper way to comment a function or method?
a doc string using the triple quote format. the format is
1. a single summary line
2. a longer description paragraph of what the function does (not how)
3. Args: section
Args:
arg1: description
arg2: description
4. Returns: section
5. Raises: section

The doc string should give enough information to write a call to the function without looking at a single line of the function's code.
what is the proper way to comment a class?
Classes should have a doc string below the class definition describing the class. If your class has public attributes, they should be documented here in an Attributes section and follow the same formatting as a function's Args section.
what is the proper way to comment a module (file)?
copyright statement, license, author list
why should you explicitly inherit from object when defining a class with no other parents?
Inheriting from object is needed to make properties work properly, and it will protect your code from one particular potential incompatibility with Python 3000. It also defines special methods that implement the default semantics of objects including __new__, __init__, __delattr__, __getattribute__, __setattr__, __hash__, __repr__, and __str__.
what is the format for naming modules?
lower_with_under.py
what is the format for naming classes?
ClassName
what is the format for naming method/function parameters
lower_with_under
what is the format for internal elements (functions, variables, classes, etc)
add a single underscore to the beginning of the regular format