Search
- Filter Results
- Location
- Classification
- Include attachments
- https://eng.libretexts.org/Bookshelves/Computer_Science/Programming_Languages/Think_Python_2e_(Downey)/02%3A_Variables_expressions_and_statements/2.05%3A_Order_of_operationsWhen an expression contains more than one operator, the order of evaluation depends on the order of operations. Parentheses have the highest precedence and can be used to force an expression to evalua...When an expression contains more than one operator, the order of evaluation depends on the order of operations. Parentheses have the highest precedence and can be used to force an expression to evaluate in the order you want. You can also use parentheses to make an expression easier to read, as in (minute * 100) / 60, even if it doesn’t change the result. So in the expression degrees / 2 * pi, the division happens first and the result is multiplied by pi.
- https://eng.libretexts.org/Bookshelves/Computer_Science/Programming_Languages/Think_Python_2e_(Downey)/19%3A_The_Goodies/19.09%3A_Gathering_keyword_argsIf you have a dictionary of keywords and values, you can use the scatter operator, ** to call a function: Without the scatter operator, the function would treat d as a single positional argument, so i...If you have a dictionary of keywords and values, you can use the scatter operator, ** to call a function: Without the scatter operator, the function would treat d as a single positional argument, so it would assign d to x and complain because there’s nothing to assign to y: When you are working with functions that have a large number of parameters, it is often useful to create and pass around dictionaries that specify frequently used options.
- https://eng.libretexts.org/Bookshelves/Computer_Science/Programming_Languages/Think_Python_2e_(Downey)/03%3A_Functions/3.12%3A_DebuggingYou are confronted with clues and you have to infer the processes and events that led to the results you see. If your hypothesis was correct, you can predict the result of the modification, and you ta...You are confronted with clues and you have to infer the processes and events that led to the results you see. If your hypothesis was correct, you can predict the result of the modification, and you take a step closer to a working program. The idea is that you should start with a working program and make small modifications, debugging them as you go.
- https://eng.libretexts.org/Bookshelves/Computer_Science/Programming_Languages/Think_Python_2e_(Downey)/01%3A_The_way_of_the_program/1.05%3A_Values_and_typesA value is one of the basic things a program works with, like a letter or a number. These values belong to different types: 2 is an integer, 42.0 is a floating-point number, and 'Hello, World!' is a s...A value is one of the basic things a program works with, like a letter or a number. These values belong to different types: 2 is an integer, 42.0 is a floating-point number, and 'Hello, World!' is a string, so-called because the letters it contains are strung together. In these results, the word “class” is used in the sense of a category; a type is a category of values. Not surprisingly, integers belong to the type int, strings belong to str and floating-point numbers belong to float.
- https://eng.libretexts.org/Bookshelves/Computer_Science/Programming_Languages/Think_Python_2e_(Downey)/09%3A_Case_study_-_word_play/9.05%3A_DebuggingAmong the words that have an “e”, you should test words with an “e” at the beginning, the end, and somewhere in the middle. By scanning the output, you might be able to catch errors, but be careful: y...Among the words that have an “e”, you should test words with an “e” at the beginning, the end, and somewhere in the middle. By scanning the output, you might be able to catch errors, but be careful: you might catch one kind of error (words that should not be included, but are) and not another (words that should be included, but aren’t).
- https://eng.libretexts.org/Bookshelves/Computer_Science/Programming_Languages/Think_Python_2e_(Downey)/08%3A_Strings/8.02%3A_lenlen is a built-in function that returns the number of characters in a string: To get the last letter of a string, you might be tempted to try something like this: The reason for the IndexError is that...len is a built-in function that returns the number of characters in a string: To get the last letter of a string, you might be tempted to try something like this: The reason for the IndexError is that there is no letter in ’banana’ with the index 6. To get the last character, you have to subtract 1 from length: Or you can use negative indices, which count backward from the end of the string. The expression fruit[-1] yields the last letter, fruit[-2] yields the second to last, and so on.
- https://eng.libretexts.org/Bookshelves/Computer_Science/Programming_Languages/Think_Python_2e_(Downey)/15%3A_Classes_and_objects/15.08%3A_GlossaryThe class object can be used to create instances of the type. An object that is stored as an attribute of another object. To copy the contents of an object, including any references to embedded object...The class object can be used to create instances of the type. An object that is stored as an attribute of another object. To copy the contents of an object, including any references to embedded objects; implemented by the copy function in the copy module. To copy the contents of an object as well as any embedded objects, and any objects embedded in them, and so on; implemented by the deepcopy function in the copy module.
- https://eng.libretexts.org/Bookshelves/Computer_Science/Programming_Languages/Think_Python_2e_(Downey)/13%3A_Case_study_-_data_structure_selection/13.11%3A_GlossaryPertaining to a program that does the same thing each time it runs, given the same inputs. Pertaining to a sequence of numbers that appears to be random, but is generated by a deterministic program. T...Pertaining to a program that does the same thing each time it runs, given the same inputs. Pertaining to a sequence of numbers that appears to be random, but is generated by a deterministic program. The process of choosing between data structures by implementing alternatives and testing them on a sample of the possible inputs. Articulating the problem can help you solve it, even if the rubber duck doesn’t know Python.
- https://eng.libretexts.org/Bookshelves/Computer_Science/Programming_Languages/Think_Python_2e_(Downey)/18%3A_Inheritance/18.07%3A_InheritanceWhen a new class inherits from an existing one, the existing one is called the parent and the new class is called the child. In this example, Hand inherits __init__ from Deck, but it doesn’t really do...When a new class inherits from an existing one, the existing one is called the parent and the new class is called the child. In this example, Hand inherits __init__ from Deck, but it doesn’t really do what we want: instead of populating the hand with 52 new cards, the init method for Hands should initialize cards with an empty list. You can use move_cards for any of these operations: self can be either a Deck or a Hand, and hand, despite the name, can also be a Deck.
- https://eng.libretexts.org/Bookshelves/Computer_Science/Programming_Languages/Think_Python_2e_(Downey)/11%3A_Dictionaries/11.05%3A_Dictionaries_and_listsFor example, if you are given a dictionary that maps from letters to frequencies, you might want to invert it; that is, create a dictionary that maps from frequencies to letters. If val is not in inve...For example, if you are given a dictionary that maps from letters to frequencies, you might want to invert it; that is, create a dictionary that maps from frequencies to letters. If val is not in inverse, that means we haven’t seen it before, so we create a new item and initialize it with a singleton (a list that contains a single element). I mentioned earlier that a dictionary is implemented using a hashtable and that means that the keys have to be hashable.
- https://eng.libretexts.org/Bookshelves/Computer_Science/Programming_Languages/Think_Python_2e_(Downey)/03%3A_Functions/3.14%3A_ExercisesWrite a function named right_justify that takes a string named s as a parameter and prints the string with enough leading spaces so that the last letter of the string is in column 70 of the display. M...Write a function named right_justify that takes a string named s as a parameter and prints the string with enough leading spaces so that the last letter of the string is in column 70 of the display. Modify do_twice so that it takes two arguments, a function object and a value, and calls the function twice, passing the value as an argument. Define a new function called do_four that takes a function object and a value and calls the function four times, passing the value as a parameter.