Docsity

Intro to Programming Python List - ANSWER...-A Python data, Exams of Health sciences

Toggle sidebar
bg1
Intro to Programming Python
List - ANSWER...-A 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 - ANSWER...-Variables 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 - ANSWER...-Python 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 - ANSWER...-Strings store characters and have many built-in convenience
methods that let you modify their content.
The len() Function - ANSWER...-Using len(some_object) returns the number of _top-
level_ items contained in the object being queried. Length of string
Print - ANSWER...-A function to display the output of a program. Using the
parenthesized version is arguably more consistent.
The range() Function - ANSWER...-The 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 - ANSWER...-A 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 - ANSWER...-Using 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() - ANSWER...-function that enabled the user to insert their string. Now
obsolete
input() - ANSWER...-function that enables user to insert data as a string
sort method - ANSWER...-x.sort() method is used to sort a list.
pf2

Partial preview of the text

Download Intro to Programming Python List - ANSWER...-A Python data and more Exams Health sciences in PDF only on Docsity!

Intro to Programming Python

List - ANSWER...-A 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 - ANSWER...-Variables 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 - ANSWER...-Python 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 - ANSWER...-Strings store characters and have many built-in convenience methods that let you modify their content. The len() Function - ANSWER...-Using len(some_object) returns the number of top- level items contained in the object being queried. Length of string Print - ANSWER...-A function to display the output of a program. Using the parenthesized version is arguably more consistent. The range() Function - ANSWER...-The 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 - ANSWER...-A 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 - ANSWER...-Using 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() - ANSWER...-function that enabled the user to insert their string. Now obsolete input() - ANSWER...-function that enables user to insert data as a string sort method - ANSWER...-x.sort() method is used to sort a list.

Distinguish method vs. a built in function - ANSWER...-function has curly braces after it, method has .'dot' notation. Why use classes? - ANSWER...-Python 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 a new variable and have it equal to your example object and use built in parameters to build your objects parameters. Methods - ANSWER...-When a class has its own functions, those functions are called methods. You've already seen one such method: init(). Functions - ANSWER...-Functions are a convenient way to divide your code into useful blocks, allowing us to order our code, make it more readable, reuse it and save some time. Also functions are a key way to define interfaces so programmers can share their code. Objects - ANSWER...-Objects are an encapsulation of variables and functions into a single entity. Objects get their variables and functions from classes. Classes are essentially a template to create your objects.