Flashcards
my program
Flashcards do conjunto (76)
- 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.
- 2pydocgenerates documentation from Python modules
- 3open()open files. Returns a file object
- 4.close()Closes file. Ex 15.
- 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.truncate()empties a file. Ex 16.
- 7write('string')writes the content of the 'string' to the
file. Ex. 16. - 8printprints a string within " " (Python 2) or within (" ") (Python 3)
- 9#comments out code
- 10Math in Python: +, - , / , *, %, <, >, <=, >=+ addition
- subtration
/ division
* multiplication
% modulo division
> less than
< greater than
>= less than or equals
<= greater than or equals - 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%dformatter: signed integer decimal
- 13%rstring (converts any python object using repr() )
- 14%sstring (converts any python object using str() )
- 15+ (for strings)concatenation operator
- 16\nEscape sequence: new line
- 17""" . . . """Can write a string on multiple new lines between three double (or single) quotes
- 18\\Escape Sequence: Backslash \
- 19\'Escape Sequence: Single quote '
- 20\"Escape Sequence: Double quote "
- 21\aEscape Sequence: ASCII bell (BEL)
- 22\bEscape Sequence: ASCII backspace (BS)
- 23\fEscape Sequence: ASCII formfeed (FF)
- 24\nEscape Sequence: ASCII linefeed (LF)
- 25\N{name}Escape Sequence: Character named name in the Unicode database (Unicode only)
- 26\rEscape Sequence: Carriage Return (CR)
- 27\tEscape Sequence: Horizontal Tab (TAB)
- 28\uxxxxEscape Sequence:
Character with 16-bit hex value xxxx
(Unicode only) - 29\UxxxxxxxxEscape Sequence:
Character with 32-bit hex value xxxxxxxx
(Unicode only) - 30\vEscape Sequence: ASCII vertical tab (VT)
- 31\oooEscape Sequence: Character with octal value ooo
- 32\xhhEscape Sequence: Character with hex value hh
- 33sys.argvThe list of command line arguments passed to a Python script
- 34importimports different python modules
- 35object.read()reads a file's contents
- 36os.path.exists(file)returns a TRUE if file exists, a FALSE if it does not
- 37functiondef function_name(*args):
function body - 38logic character for "and"and
- 39logic character for "or"or
- 40logic character for "not"not
- 41!=not equal
- 42==equals, tests equivalence; not used to assign an object to a variable
- 43if statement:if clause:
code
elif clause:
code
else: - 44Lista container of things ordered from first to last
- 45list.append( element )inserts an element into the list
- 46range (stop)range(stop) = number of integers to generate starting at zero and stopping just before the stop integer you enter
- 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.
- 48while loopkeeps executing as long as boolean expression is true.
while clause is true:
code body - 49list = [ element1, elment2, ... ,elementN]how to setup a list
- 50list[number of element]how to access an element of a list. Numbering starts at 0
- 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. - 52dict.item()The method items() returns a list of dict's (key, value) tuple pairs. (Ex. 39)
- 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) - 54classTell Python to make a new type of thing
- 55objectTwo meanings: the most basic type of thing and any instance of some thing
- 56instancewhat you get when you tell Python to create a class
- 57defhow you define a function inside a class
- 58selfInside the functions in a class, self is a variable for the instance/object being accessed
- 59inheritanceThe concept that one class can inherit traits from another class, much like you and your parents
- 60compositionthe concept that a class can be composed of other classes as parts, much like how a car has wheels
- 61attributeA property classes have that are from composition and are usually variables
- 62is-aA phrase to say that something inherits from another, as in a "salmon" is-a "fish."
- 63has-aA phrase to say that something is composed of other things or has a trait, as in "a salmon has-a mouth."
- 64class X(Y)Make a class name X that is-a Y
- 65class X(object): def __init___(self, J)class X has-a __init__ that takes self and J parameters
- 66class X(object): def M(self, J)class X has-a function named M that takes self and J parameters
- 67foo = X()Set foo to an instance of X
- 68foo.M(J)From foo get the M function and call it with parameters self, J
- 69foo.K = QFrom foo get the K attribute and set it to Q
- 70list comprehensiona list building loop expressed in one-line, e.g.,
[expr for var in iterable]
[n**2 for n in range(12)] - 71iter()checks whether the object has an iterator interface. If so, you can iterate over it with a for loop, etc.
- 72enumerate()for when you need to iterate not only over values in an array, but also their indexes.
- 73zip()allows you to iterate over multiple lists at the same time, e.g., by zipping to arrays of equal length together
- 74str.isalnum()Checks wether is string is made up of only alpha-numeric characters and returns:
True (if only alpha-numeric) or False - 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—
Informações
- Descrição
- None Programming FlashCards sobre my program, criado por Jared Carlson em 09-08-2016.
- Criado por
- Jared Carlson
- Visualizações
- 0
- Avaliação