GoConqr has a new look! Let us know what you think.

Flashcards

my program

Jared Carlson Programming None English 76 cards

Cards in this deck (76)

  1. 1raw_input([prompt])If the prompt argument is present, it is written to standard output without a trailing newline. The function then reads a line from input, converts it to a string (stripping a trailing newline), and returns that. When EOF is read, EOFError is raised.
  2. 2pydocgenerates documentation from Python modules
  3. 3open()open files. Returns a file object
  4. 4.close()Closes file. Ex 15.
  5. 5.readline()reads one line of a text file. Ex 16. Each time you do f.readline() you're reading a line from the file, and moving the read head to right after the \n that ends that line.
  6. 6.truncate()empties a file. Ex 16.
  7. 7write('string')writes the content of the 'string' to the
    file. Ex. 16.
  8. 8printprints a string within " " (Python 2) or within (" ") (Python 3)
  9. 9#comments out code
  10. 10Math in Python: +, - , / , *, %, <, >, <=, >=+ addition
    - subtration
    / division
    * multiplication
    % modulo division
    > less than
    < greater than
    >= less than or equals
    <= greater than or equals
  11. 11%marks start of specifier (formatter) within string
    or
    outside of a string it indicates a list of variables follows to substitute in place of formatters inside the string.
  12. 12%dformatter: signed integer decimal
  13. 13%rstring (converts any python object using repr() )
  14. 14%sstring (converts any python object using str() )
  15. 15+ (for strings)concatenation operator
  16. 16\nEscape sequence: new line
  17. 17""" . . . """Can write a string on multiple new lines between three double (or single) quotes
  18. 18\\Escape Sequence: Backslash \
  19. 19\'Escape Sequence: Single quote '
  20. 20\"Escape Sequence: Double quote "
  21. 21\aEscape Sequence: ASCII bell (BEL)
  22. 22\bEscape Sequence: ASCII backspace (BS)
  23. 23\fEscape Sequence: ASCII formfeed (FF)
  24. 24\nEscape Sequence: ASCII linefeed (LF)
  25. 25\N{name}Escape Sequence: Character named name in the Unicode database (Unicode only)
  26. 26\rEscape Sequence: Carriage Return (CR)
  27. 27\tEscape Sequence: Horizontal Tab (TAB)
  28. 28\uxxxxEscape Sequence:
    Character with 16-bit hex value xxxx
    (Unicode only)
  29. 29\UxxxxxxxxEscape Sequence:
    Character with 32-bit hex value xxxxxxxx
    (Unicode only)
  30. 30\vEscape Sequence: ASCII vertical tab (VT)
  31. 31\oooEscape Sequence: Character with octal value ooo
  32. 32\xhhEscape Sequence: Character with hex value hh
  33. 33sys.argvThe list of command line arguments passed to a Python script
  34. 34importimports different python modules
  35. 35object.read()reads a file's contents
  36. 36os.path.exists(file)returns a TRUE if file exists, a FALSE if it does not
  37. 37functiondef function_name(*args):
    function body
  38. 38logic character for "and"and
  39. 39logic character for "or"or
  40. 40logic character for "not"not
  41. 41!=not equal
  42. 42==equals, tests equivalence; not used to assign an object to a variable
  43. 43if statement:if clause:
    code
    elif clause:
    code
    else:
  44. 44Lista container of things ordered from first to last
  45. 45list.append( element )inserts an element into the list
  46. 46range (stop)range(stop) = number of integers to generate starting at zero and stopping just before the stop integer you enter
  47. 47range(start, stop, step)generate integers starting at start integer entered and ending just before the stop integer you enter proceeding by the step size you indicate. If no step size is entered, a step size of 1 is assumed.
  48. 48while loopkeeps executing as long as boolean expression is true.
    while clause is true:
    code body
  49. 49list = [ element1, elment2, ... ,elementN]how to setup a list
  50. 50list[number of element]how to access an element of a list. Numbering starts at 0
  51. 51Rules for If-StatementsEvery if-statement must have an else.
    If this else should never run because it doesn't make sense, then you must use a die function in the else that prints out an error message and dies, just like we did in the last exercise. This will find many errors.
    Never nest if-statements more than two deep and always try to do them one deep.
    Treat if-statements like paragraphs, where each if-elif-else grouping is like a set of sentences. Put blank lines before and after.
    Your boolean tests should be simple. If they are complex, move their calculations to variables earlier in your function and use a good name for the variable.
  52. 52dict.item()The method items() returns a list of dict's (key, value) tuple pairs. (Ex. 39)
  53. 53dict.get()The method get() returns a value for the given key. If key is not available then returns default value None.
    Example: cities.get('TX', 'Does Not Exist'). (Ex. 39)
  54. 54classTell Python to make a new type of thing
  55. 55objectTwo meanings: the most basic type of thing and any instance of some thing
  56. 56instancewhat you get when you tell Python to create a class
  57. 57defhow you define a function inside a class
  58. 58selfInside the functions in a class, self is a variable for the instance/object being accessed
  59. 59inheritanceThe concept that one class can inherit traits from another class, much like you and your parents
  60. 60compositionthe concept that a class can be composed of other classes as parts, much like how a car has wheels
  61. 61attributeA property classes have that are from composition and are usually variables
  62. 62is-aA phrase to say that something inherits from another, as in a "salmon" is-a "fish."
  63. 63has-aA phrase to say that something is composed of other things or has a trait, as in "a salmon has-a mouth."
  64. 64class X(Y)Make a class name X that is-a Y
  65. 65class X(object): def __init___(self, J)class X has-a __init__ that takes self and J parameters
  66. 66class X(object): def M(self, J)class X has-a function named M that takes self and J parameters
  67. 67foo = X()Set foo to an instance of X
  68. 68foo.M(J)From foo get the M function and call it with parameters self, J
  69. 69foo.K = QFrom foo get the K attribute and set it to Q
  70. 70list comprehensiona list building loop expressed in one-line, e.g.,
    [expr for var in iterable]
    [n**2 for n in range(12)]
  71. 71iter()checks whether the object has an iterator interface. If so, you can iterate over it with a for loop, etc.
  72. 72enumerate()for when you need to iterate not only over values in an array, but also their indexes.
  73. 73zip()allows you to iterate over multiple lists at the same time, e.g., by zipping to arrays of equal length together
  74. 74str.isalnum()Checks wether is string is made up of only alpha-numeric characters and returns:
    True (if only alpha-numeric) or False
  75. 75continuewhen use in a loop, if the condition is satisfied, "continue" will stop that iteration of the loop and continue with the next iteration (compare this with "break" and "pass")
  76. 76—

Information

Description
None Programming Flashcards on my program, created by Jared Carlson on 09/08/2016.
Created by
Jared Carlson
Views
0
Rating

Feedback

What is it about?

What do you think of the new look?

How do you like it?