Python Flashcards
What will happen if you try to print a variable that was not defined?
As the variable was not defined, you will get an error message like this one:
NameError: name ‘z’ is not defined
What does those operators mean?
x += 2
x -= 2
Equivalent: x = x + 2
Equivalent: x = x - 2
What type of data you get when you divide a integer by another integer?
A float
What happens when you convert a Float to an Int
The decimal part of the number is cut off
print(int(32.7))
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
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.
What is a string?
String is a immutable ordered sequence of characters (E.G. letters, numbers, spaces and symbols)
Which function in python would you use to find out the number of characters of a string?
len()
Why is it important to define what type of data you are going to use for different purposes?
Because for each data type there is different built in functions that work with them.
What are methods in Python?
A method in Python behaves similarly to a function. Methods actually are functions that are called using dot notation.
In the example first_name.islower() is there an argument along with the islower() method?
Yes, usually teh argument goes inside the parenthesis, but in this case, the argument is “disguised”as “first_name”.
What does the following error mean? “SyntaxError: unexpected EOF while parsing”
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.
In Python there are containers of data, which contains other data types and even other containers.
What is consists the container of data List?
List is a data type for mutable ordered sequences of elements.
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?
The lower index is inclusive and the upper index is exclusive.
Lists and strings both support indexing, slicing and IN operator.
So, whats the difference between them?
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 to functions max() works differently with lists of words and numbers?
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