Save
Busy. Please wait.
Log in with Clever
or

show password
Forgot Password?

Don't have an account?  Sign up 
Sign up using Clever
or

Username is available taken
show password


Make sure to remember your password. If you forget it there is no way for StudyStack to send you a reset link. You would need to create a new account.
Your email address is only used to allow you to reset your password. See our Privacy Policy and Terms of Service.


Already a StudyStack user? Log In

Reset Password
Enter the associated with your account, and we'll email you a link to reset your password.
focusNode
Didn't know it?
click below
 
Knew it?
click below
Don't Know
Remaining cards (0)
Know
0:00
Embed Code - If you would like this activity on your web page, copy the script below and paste it into your web page.

  Normal Size     Small Size show me how

Objects and Classes

Python

QuestionAnswer
object In Python every value is stored in memory as an object. It is useful to think of an object as a container for the value that sits inside your computer's memory.
object type indicates kind of values object can hold and operations that can be performed on the object. Examples: integer (int), floating point (float), Boolean (bool), string (str), and list (list) type() function can be used to determine an object's type
variable and object type variables do not have types the objects variables refer to have types
object-oriented Python programming language is said to be object-oriented because values are always stored in objects. In programming languages other than Python, values of certain types are not stored in abstract entities such as objects but explicitly in memory.
class The term class is used to refer to types whose values are stored in objects. Because every value in Python is stored in an object, every Python type is a class. In this book, we will use class and type interchangeably.
float represents real numbers as fractions with finite decimal representations
number type and algebraic expressions If both operands x and y (are integers, the result is an integer. If one of the operands is a float value, the result is a float value. For division (/), the result is a float value, regardless of the operands.
7 comparison operators for numbers < Less than <= Less than or equal > Greater than >= Greater than or equal == Equal != Not equal
constructor explicitly instantiate object type x = int() float(), list(), and str()
Implicit type conversion float contains integer contains boolean If an algebraic or logical expression involves operands of different types, Python will convert each operand to the type that contains the others.
Operator Precedence List definition Indexing operator Exponentiation Positive, negative signs Product, division, integer division, remainder Addition, subtraction Comparisons, including membership and identity tests Boolean NOT Boolean AND Boolean OR
Explicit Type Conversions >>> int(3.4) 3 >>> float(3) 3.0 >>> str(2.72) ‘2.72’
methods We have a list object, pets, followed by a dot (.), followed by the method (function) call. EX: pets.append(‘guinea pig’) The list method append() is called on the list object pets with string input ‘guinea pig’.
Python Standard Library Consists of thousands of functions and classes organized into components called modules that relate to particular application domain. More than 200 built-in modules together form the Python Standard Library.
Module math To use a math module function >>> import math sqrt(x) ceil(x) (i.e., the smallest integer = x) floor(x)(i.e., the largest integer = x) cos(x) cos(x) sin(x) sin(x) log(x, base) logbase(x) pi 3.141592653589793 e 2.718281828459045
Module fractions >>> import fractions >>> a = fractions.Fraction(3, 4) >>> b = fractions.Fraction(1, 2) As with other numbers, Fraction objects can be added, and the result is a Fraction object: >>> c = a + b >>> c Fraction(5, 4)
float vs fraction the range of values that float objects can store is limited The range of values representable with fractions.Fraction objects is much, much larger and limited only by the available memory expressions involving float values evaluate much faster
Created by: kbaldwin
Popular Computers sets

 

 



Voices

Use these flashcards to help memorize information. Look at the large card and try to recall what is on the other side. Then click the card to flip it. If you knew the answer, click the green Know box. Otherwise, click the red Don't know box.

When you've placed seven or more cards in the Don't know box, click "retry" to try those cards again.

If you've accidentally put the card in the wrong box, just click on the card to take it out of the box.

You can also use your keyboard to move the cards as follows:

If you are logged in to your account, this website will remember which cards you know and don't know so that they are in the same box the next time you log in.

When you need a break, try one of the other activities listed below the flashcards like Matching, Snowman, or Hungry Bug. Although it may feel like you're playing a game, your brain is still making more connections with the information to help you out.

To see how well you know the information, try the Quiz or Test activity.

Pass complete!
"Know" box contains:
Time elapsed:
Retries:
restart all cards