W2 - Boolean, Precedence, Intro to Sequences, Type Casting Flashcards
What are True and False equal to?
1 and 0 respectively
What is the return type for the expression 4 == x? What are the possible values?
bool, and either True of False (CAPITAL FIRST LETTERS)
What will this code yield?
»> myval = 3 < 5
»> myval + 7
_______?
8, the boolean True is equivalent to a 1
what are the and/or operators?
literally just the words “and” and “or”
order of precedence for operators (highest = top, lowest = bottom)
parentheses
exponentiation
negation
multiplication/division (including modulus)
addition/subtraction
relations (<, >, <=, ==, !=, etc)
not
and
or (nandor!)
define associativity
same precedence, therefore move left to right (like PEMDAS)
what are the logical operators?
not, and, or (nandor)
strings returned with any quotation marks around them are returned with (double/single) marks
single
Show the result:
»> myname = ‘monty’
»> len(myname)
5
Show the result:
»> myname = ‘monty’
»> myname[0]
would result in ‘m’ (with the single quotation marks)
Show the result:
»> 3 in [44, 3, 5, -9]
True (rmr, capital letters!)
when should you use snake case?
when describing a unit of a variable in the variable name (ex. timeSinceStarted_ms)
Which of the following are true?
1. the = operator is used for both assignments and equality
2. Strings can be compared using the relational operators
3. The first character in a string variable mystring is mystring[1]
4. The len function can be used for both strings and lists
2 and 4 are correct
True/false: Strings can be modified
false, they are immutable
are lists mutable?
yes!