Python Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What will happen if you try to print a variable that was not defined?

A

As the variable was not defined, you will get an error message like this one:
NameError: name ‘z’ is not defined

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does those operators mean?
x += 2

x -= 2

A

Equivalent: x = x + 2

Equivalent: x = x - 2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What type of data you get when you divide a integer by another integer?

A

A float

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What happens when you convert a Float to an Int

A

The decimal part of the number is cut off

print(int(32.7))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

If you add 0.1 together why do you get a bigger number than the sum of each number?
For instance?
INPUT:
print(0.1 + 0.1 + 0.1)

OUTPUT:
3.000000000000004

A

Because a float can represent an enormous range of numbers. In order to fit it in a computer memory, a float, actually, is an aproximation of the number it represents in python.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a string?

A

String is a immutable ordered sequence of characters (E.G. letters, numbers, spaces and symbols)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Which function in python would you use to find out the number of characters of a string?

A

len()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Why is it important to define what type of data you are going to use for different purposes?

A

Because for each data type there is different built in functions that work with them.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are methods in Python?

A

A method in Python behaves similarly to a function. Methods actually are functions that are called using dot notation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

In the example first_name.islower() is there an argument along with the islower() method?

A

Yes, usually teh argument goes inside the parenthesis, but in this case, the argument is “disguised”as “first_name”.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does the following error mean? “SyntaxError: unexpected EOF while parsing”

A

This message is often produced when you have accidentally left out something, like a parenthesis. The message is saying it has unexpectedly reached the end of file (“EOF”) and it still didn’t find that right parenthesis. This can easily happen with code syntax involving pairs, like beginning and ending quotes also.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

In Python there are containers of data, which contains other data types and even other containers.

What is consists the container of data List?

A

List is a data type for mutable ordered sequences of elements.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

You can pull more than one value of a list using slicing. Although, you must know that the upper and lower index informed behave differently. How?

A

The lower index is inclusive and the upper index is exclusive.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Lists and strings both support indexing, slicing and IN operator.

So, whats the difference between them?

A

Strings are sequences of letters, while list elements can be any type of object.

One more sutil difference, is that lists can be modified, but strings can’t.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How to functions max() works differently with lists of words and numbers?

A

When working with a list of numbers, max() will bring the largest number in the list.

When working with list of words, max() will bring the word that starts with the biggest letter considering its index in the alphabet

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

When using the method join() in a list of strings, how you separate each element with a line break(enter)?

A

Using “\n”

17
Q

What is a tuple?

A

A data type for immmutable ordered sequence of elements. Used to store related pieces of informations like latitude and longitude.

18
Q

What consists tuple unpacking?

A

You can use tuple unpacking to assign the information from a tuple into multiple variables without having to access them one by one and make multiple assignment statemente:

Instead of this:

dimensions = 52, 40, 100
length, width, height = dimensions
print(“The dimensions are {} x {} x {}”.format(length, width, height))

You can use this:

length, width, height = 52, 40, 100
print(“The dimensions are {} x {} x {}”.format(length, width, height))

Tuples do not require parenthesis.

19
Q

Knowing that a set is a data type for mutable unordered collections of unique elements, how would you use a set structure to get the unique values of a list with repeated values?

A

numbers = [1, 2, 6, 3, 1, 1, 6]
unique_nums = set(numbers)
print(unique_nums)

20
Q

What is an Iterable?

A

An object that can return one of its elements at a time.