Python

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

What does Name[::2]: give you?

Shows the variable that is attached to every other index element

What is escape sequences?

Strings that are difficult to input

What are lists and tuples

They are compound data types

How do you convert a list to a set that has unique elements?

nameoftheset=set(nameofthelist)

what code allows you to add something to every item in a column?

nameofthevariableassignedtodata['nameofcolumn']=nameofthevariableassignedtodata['nameofcolumn']+thethingyouwanttoadd

does a function always need a return statement

no

can we just set one tuple equal to another one?

no they are immutable and thus a new one should be created

what does each line in the csv file represent?

row

Consider the string A='1934567', what is the result of the following operation A[1::2]

'946'

Consider the following list B=[1,2,[3,'a'],[4,'b']], what is the result of the following:B[3][1]

'b'

What command do we use to convert a string to a list?

'name of string'.split( )

what would NT[2] [1] return if NT =(1,2, ('pop', 'rock'), (3,4),('disco',(1,2)))?

'rock'

How do we open and close a the code segment len?

(( ))

Consider the following tuple A=(1,2,3,4,5), what is the result of the following:A[1:4]:

(2, 3, 4)

what would NT[2][1][0] return if NT =(1,2, ('pop', 'rock'), (3,4),('disco',(1,2)))?

r

What does the following code do? A.reomove('NSYNC')?

removes the element of NSYNC from the list A

What is the result of the following code? type(set(list)

set

How do we designate the character that separates the string into a list?

the 'string'.split(',') would make the comma the delimiter.

what do we use to construct a class?

the function, __init__

What does sys.float_info tell you

the limitations in your numbers

what does the self parameter refer to?

the newly created instance of a class

what do we use to separate multiple words in our variables?

the underscore _

What makes sets different than lists and tuples?

they are not ordered

Is it true or false that an integer 1 is a separate object than integer 2?

true

what does a scope of a variable refer to?

where the variable is accessible in a particular program

what will the nameofthefileobject.mode tell us

whether it is in read, write, or append

Can you only use double quotes for strings?

yes

Is it true that spaces can be digits, spaces, special characters, and letters?

yes

can you multiply a string by a number in a function

yes

with file1.name give me the name of the file object 1?

yes

can we put one tuple in another tuple?

yes, it is called nesting

can we nest tuples in lists?

yes, we can put anything we want in there

what is the multiplication operator?

*

what is the exponential operator ?

**

what is the result of the following code segment: 1//2

0

Consider the string Name="ABCDE", what is the result of the following operation Name.find("B")

1

what does the following function return: len([sum([0,0,1])]) ?

1

what is the radius attribute after the following code block is run: RedCircle=Circle(10,'red') RedCircle.radius=1

1

If price = 10, what will print(price) return?

10

What will print(price) return if we set price = 10, then price = 11

11

What is the value of x after the following lines of code: x=1 x=x+1

2

What will the function, c=add1(10) c=add1(2) return?

3

what would NT[3] [0] return if NT =(1,2, ('pop', 'rock'), (3,4),('disco',(1,2)))?

3

what is the radius attribute after the following code block is run: BlueCircle=Circle(10,'blue') BlueCircle.add_radius(20)

30

What the output in Name.find('el'):5 ?

5

what is the result of the following: len(("disco",10,1.2, "hard rock",10))?

5

what is the equal operator ?

==

what is the difference between a Parameter and an Argument?

A Parameters are passed during the definition of function while Arguments are passed during the function call. A parameter is a variable in a method definition. When a method is called, the arguments are the data you pass into the method's parameters. Parameter is variable in the declaration of function. Argument is the actual value of this variable that gets passed to function.

What does \n in a print command represent?

A new line

What does multiplying a string by a number do?

A new string is the replicated version of the old string.

What does \t in a print command represent?

A tab in the string sequence

What does putting an r before the sequence in the parenthesis do?

Allows backward slashes to be backward slashes and not a start of a escape sequence.

Where does a range function end?

At one to the last

What does B=A.replace('sam' 'john') do to A If A is equal to 'sam is the best brother'

B: 'john is the better brother

Why should a name of a function be descriptive of what it does?

Because the function syntax can be arbitrarily decided upon.

What are used for accessing index?

Brackets [ ]

What do we call the parenthesis in a function in python?

Calling or executing a function

What does the + sign do to a string?

Concatenate

What are floats?

Decimals

For the list, names=['sam', 'john', pari, gus], create a loop.

For names in names in names: name

where are variables that are defined outside of function said to be defined?

Global scope

What happens if we cast a Boolean to an integer or a float?

If it is False, we get a zero. If the Boolean is True, we get a one.

What can cause the NameError to show up?

If you misspell the function

What does the code B=A.upper() do to B if A='sam'

It makes the B string the uppercase version of A

what does calling the function mean?

It means that you have defined its parameter and it has returned a value. For example, if the function is: def add1(a): b=a+1 return b calling it would be to type add1(define a)

What is required from programmers when coding a string?

It must be enclosed in quotation marks so that the expression is not recognized as something else

what does the sorted function do?

It returns a new, sorted list. it does not change the original list.

Where does a range function start?

It starts at zero

What does the while loop function do?

It stops the iteration when the conditions are not met

What happens if you cast a zero and then a one into a Boolean?

It would return a False and True respectively.

What would the casting command----------int(True)---------return?

It would return a one

What is the command-------int(3.99)--------return?

It would return a three

What would the command----------int("A")-------return?

It would return an error message

what do we use to create dictionaries?

Just like a list, we use brackets

In Python, if you executed name = 'Lizz', what would be the output of print(name[0:2])?

Li

What is the argument in the following code and what does it do? A.add('NSYNC')

NSYNC is the element being added to the list A

How do find out the variable that each index in your string is assigned to?

Name[index]

What is the command to read a line from the file?

Nameofthefileobject.readine()

How do we output every line as an elements in a list with what code?

Nameofthefileojject.readline()

Is the code-------- if ("option1" == "option 2")then------true?

No because the quotations make the options treated as the string type and thus a word

Does python know about your error before it runs code?

No, Python interprets your code line by line as it executes it

Do we have to use an index to refer to an object in the list?

No, you can name the object directly.

What are numbers in mathematical operation in Python called?

Operands

What are the math symbols in Python referred to as?

Operators

How do we check to see if a file object is closed

Print(Nameofthefileobject.closed)

What denotes the name of the variable in Python?

The colon

Why do you have to be careful when you cast a float to an integer?

The conversion truncates to zero. So if the numbers on the right side of the decimal are large enough, you can lose a lot of information.

What are the two components of a loop function ?

The for and in command

What are logic operators?

They take Booolian values and produce different Boolian values.

What is type casting?

To change the type in python

What does concatenate mean?

To link (things) together in a chain or series.

What is the number symbol, #, used for?

To write comments in Python.

What method do we use to get all the keys?

VARIABLENAME.keys()

When can we not cast a string to an integer?

When the string contains a non-integer

When can we cast a string to an integer?

When the string contains an integer value, e.g., int('1'):1

What is an example of a SyntaxError?

When we forget to close the string with quotation mark

How do we include all elements from two sets?

With the union command

What are strings treated as?

Words

can we use the input function to print something?

Yes, if we put the question in the form of a string and a space.

is python a cases sensitive language?

Yes, it matters if we use lower case and upper case in python

What is the result of the following: "Hello Mike".split()

["Hello","Mike"]

what is a list represented by?

[brackets]

What kind of type returned from an in command?

a boolean

If x=2.66, what does the--------type(x)-------return?

a float

What is the object type of 12.0

a float

When a function is specific to an object, what it is referred to as?

a method

what is draw circle

a method for the class

what is an expression?

a piece of code that produces something

what is the screen called where you see all the code

a terminal

what does each object have?

a type, internal data presentation, a set of specific procedures for interaction (function methods), and they are an instance of a particular type

what is the output of the following lines of code: def Print(A): for a in A: print(a+'1') Print(['a','b','c'])

a1 b1 c1 because the functions concatenates a string

For x in ['a', 'b', 'c', 'd']: print(x+a) would return what in a loop?

aa ba ca da

The method append does the following:

adds one element to a list

what are two things that a function contains?

an indent and code block

what is the difference between an object and a type?

an object is an specific type

What is binding a string?

assigning a variable to a variable

What does \\ in a print command represent?

backward slash

why do we want to use the open with function?

because it closes the file after it is accessed

What would the command---------type(True):------------return?

bool

how do we create a file object and obtain the data from a txt file?

built-in open function

What do you put the elements of a set in?

curly brackets

what are the parameters in an __init__ function referring to?

data attributes of a class

how do we change the data type in Python for a whole column?

data['column'] = data['column'].astype('datatype')

what are the two main words in a function?

def and return

what is filestuff=File1.read() in different code segments

filestuff is the variable that is assigned to the read code segment and can be printed. File1 is the name of the object file

how do we see the raw string of a file?

follow the file name by a colon

What would be the syntax for an if statement relating to entering a club that only allows people over 18?

if(age>18): print('you can enter') print('move on')

How do we check the Python version?

import sys and then print(sys.version)

what is the method of accessing an element in a tuple called?

indexing

What does-------type(2.22)------ return?

int

name the most amount of data types

int, float, string, list[], dictionaries{}, boolean, and they are all objects

the attributes surrounded by underscore resulting from the dir function are for what?

internal use, not to be concerned with

what does the code append do for the list ?

it adds only the first element of the list

what can we do with nameoffileobject.name ?

it allows us to the get the name of the file object, which is its data attribute

What is the advantage of using the with statement to open a file

it automatically closes the file object

What is the elif statement?

it is just another if statement

what is an identifier?

it is the name of your variable

what happens when a variable is not defined within a function?

it will use the value in a global scope

what is the type of the following: ["a"]

list

What is an important difference between lists and tuples?

lists are mutable

can you read a file outside of an indent?

no

If price = 10, what will print('price') return?

price

How do we print the type of each index in a tuple?

print(type(name of tuple[index number]))

What are integers?

A type of data representation in python

What is a good analogy for if statements?

If the people in the line are eighteen, they get in. If the people in the line are not eighteen, they move on.

What are the two values that a Boolean can take?

True or False (make sure to always use upper case)

What is a practice with assigning names of variables?

Use meaningful name so that you do not have to keep track of what the variable is doing, such as total_hr=total_min / 60

What method do we use to get all the values?

VARIABLENAME.values()

How do we add a value to the dictionary?

VARIABLOFTHEDICTIONARY['new key']='newvalue'

if A is a list what does the following syntax do: B=A[:]?

Variable B references a new copy or clone of the original list A

How do we access different elements of a tuple

Via an index just like strings

Why do we always have to assign variables to things?

We assign variables to things so that we can make do things with the variables, such as print(nameofvariable)

What does a string being immutable means?

We cannot change value of the string. But you can concatenate a new string.

What do we do for integer division in Python?

We use //

Outlines we have to set the attributes to create objects

What are classes

What does an error message tell you?

What kind it was and where it occurred

What doe the function input() do?

Whatever value the user enters, it will return

What does the following code return if the element Who is not included in the list A?

'Who' inA

what is the result of the following: "123".replace("12", "ab")

'ab3'

What is the inequality operator?

!=

How is the documentation in the code block that describes what the function calls distinguished?

""" """

In Python, what is the result of the following operation: '1'+'2'

'12'

what is the result of the following : str(1+1)

'2'

how is a list different than a dictionary?

Dictionary uses keys, which are usually characters and not integers like in a list.

What is the type of the number 0?

Integer(int) because there are

What are some different important types in Python?

Integers, floats, and words (a form of a string), and Booleans

what does an asterisk do to a parameter in a function?

It allow us to input a variable amount of elements

What is sys and what must we always do before using it?

It is a built-in module that contains many systems-specific parameters and functions. It is always explicitly imported.

what is a Boolean?

It is a dichotomous variable, i.e., it can take two values

what kind of function is sort?

It is a method since it only applies to lists that need to be in order.

What is an expression?

It is a piece of code that produces an output

What is a sequence of characters?

It is called a string expression

What is an equality operator, and what does it do?

It is denoted by either >, <, >=, <=, ==, and it checks whether two things are equal. These operators are Boolians.

What is slicing?

It is when we name the variable up to a certain index element

What does the code, for i,x in enumerate return?

It loops through the list it is attached to and will show each element of the list and its corresponding index

What does Square=['blue", 'black'] Newsquares=[ ] i=0 While(squares[i]=='orange'): Newsquares.append(squares[i]) i=i+1 do?

It loops through the list of squares and appends them to the new list called the Newsquares. The loop, however, stops when the condition of 'orange' is not met

what is the second argument, which is a parameter, in the open function?

The Mode, which is r for reading, w for writing, and a for appending

What does \ represent?

The beginning of escape sequences.

what is the first argument in the open function?

The file path, which is made of the file directory and the file name.

What are the function and the string in the following code segment: print('Hello, Python')

The function is print( ), and the 'Hello, Python' is the string that is passed as an argument to instruct Python on what to print

What does len( 'string' ) = return?

The number of elements in the string, which here it is 6

What does the or operator do?

The or operator is a logic operator because it uses two Boolina value to produce a new Boolian value.

what does the sort function do?

The original list is sorted

What if a substring is not in the sequence but you use the find Name.find('') to find it?

The output is -1

What does the file_stuff=File1.read() do?

The read method stores the value of the file object, File1, into the variable file_stuff as a string

What do expressions explain?

The type of operation computer performs, such as mathematical operations

What do we use to indicate a start of a new word?

The underscore

What will the code Name[0:5:2] return?

The variable that is attached to every other element of the index up to the 4th index element

What do the sequence methods do to strings?

They apply to lists and tuples within a string

What is one difference of lists from tuple?

They are mutable

What is the relationship between the else statement and the if statement?

They are only activated if the other one is false

what can values be?

They can be mutable, immutable, and duplicates

What is unique about sets?

They do not contain duplicates

What do the string methods apply to?

They don't apply to lists and tuples

what is a general purpose function?

They don't belong to any function

what should the keys be like?

They should be immutable and unique

Can we cast an integer into a string?

Yes

Can we use equality operators with strings?

Yes

consider the following list : A=["hard rock",10,1.2] what will list A contain after the following command is run: del(A[0])?

[10, 1.2]

How are values in a dictionary separated from the keys?

by a colon

How do we find what is shared between two sets?

by combining them with the &

How can we see the data type of the object in Python expression?

by the type command

what do you call the space between the def syntax and the return syntax in a function?

code block

what is the action called when you assign a value to the argument in a function, the parameter (parameter with the math meaning of being an assigned value, not the technical meaning and statistical meaning, which defines an integral or a numerical characteristic of a population respectively)?

defining the function

If A=['hard rock', 10, 1.2] what command removes something in a list A?

del(A[0])

What is an object type

different ways Python represents data, such as number or strings for words and integers for numbers

what do we use to find the list of data attributes and methods associated with a class?

dir function

What is the argument in the code segment Name.find('el'):5 ?

el

What is a useful function to iterate data?

enumerate

what do we use to add to a list?

extend command

What does 5,the output, represent in the Name.find('el'):5?

first corresponding index to the sequence of the substring

What is the type of the variable x after the following: x=1/1

float

How do you cast a float type into an integer?

float(2):2.0

Given myvar = 'hello' , how would you convert myvar into uppercase?

myvar.upper()

What code segment creates a tuple?

name of tuple = ('string', int, float)

what is one thing we can do with dictionaries?

we can assign them to a variable

what is the enumerate command useful for?

we can use it in a function to iterate through a list

what do we use to change lists?

we use brackets just like indexing.

What do you do since you can't have an empty body in Python?

we use the keyword pass

What is the difference between complied languages and interpreted language

when the warning for the errors are shown

How do you display the function name and the documentation that you can otherwise put between three quotation marks?

with the help command

How do we find out if an element we are looking for is in a dictionary?

with the in command 'nameofthingwearelookingfor' in VARIABLEOFDICTIONARY


Ensembles d'études connexes

Quizlet Review: Causes, Events & People of the Civil War

View Set

Regional Divisions of the Spinal Cord

View Set

QUIZ 2: THE WORK OF JESUS CHRIST

View Set

PICAT EXAM STUDY GUIDE: ARITHMETIC REASONING #1

View Set