

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Intro to Programming Python. Intro to Programming Python.
Typology: Exams
1 / 3
This page cannot be seen from the preview
Don't miss anything!


List - ANSWERA Python data type that holds an ordered collection of values, which can be of any type. This is equivalant to an "array" in many other languages. Python lists are "mutable," implying that they can be changed once created. Variables - ANSWERVariables are assigned values using the '=' operator, which is not to be confused with the '==' sign used for testing equality. A variable can hold almost any type of value such as lists, dictionaries, functions. Functions - ANSWERPython builds functions using the syntax: def function_name(variable): Functions can be stand-alone or can return values. Functions can also contain other functions. Strings - ANSWERStrings store characters and have many built-in convenience methods that let you modify their content. The len() Function - ANSWERUsing len(some_object) returns the number of top-level items contained in the object being queried. Length of string Print - ANSWERA function to display the output of a program. Using the parenthesized version is arguably more consistent. The range() Function - ANSWERThe range() function returns a list of integers, the sequence of which is defined by the arguments passed to it. Used in for loops.
While Loops - ANSWERA While loop permits code to execute repeatedly until a certain condition is met. This is useful if the number of iterations required to complete a task is unknown prior to flow entering the loop. The str() Function - ANSWERUsing the str() function allows you to represent the content of a variable as a string, provided that the data type of the variable provides a neat way to do so. str() does not change the variable in place, it returns a 'stringified' version of it. raw_input() - ANSWERfunction that enabled the user to insert their string. Now obsolete input() - ANSWERfunction that enables user to insert data as a string sort method - ANSWERx.sort() method is used to sort a list. Distinguish method vs. a built in function - ANSWERfunction has curly braces after it, method has .'dot' notation. Why use classes? - ANSWERPython is an object-oriented programming language, which means it manipulates programming constructs called objects. You can think of an object as a single data structure that contains data as well as functions Class Syntax - ANSWER•call class then class name (parameter) • then create a function def__init with 'self' as the 1st parameter comma then 2nd parameters. •call self.name = name and self.occupation = occupation •create