Python Flashcards
\
Backslash. Prints one backslash.
'
Single quote. Prints a single quote.
"
Double quote. Prints a single double quote.
\a
Bell. Sounds the system bell.
\n
Newline. Moves the cursor to the beginning of next line.
\t
Horizontal tab. Moves cursor forward one tab stop.
+
Addition. Combines two strings or adds two integers.
-
Subtraction.
*
Multiplication. Multiplies a string or integer.
/
Division (true).
//
Division (integer). Divides without a remainder.
%
Modulus. Gives just the remainder.
input ( )
Gets text from the user. Returns the answer as a string.
upper ( )
Returns uppercase version of the string.
lower ( )
Returns lowercase version of the string.
swapcase ( )
Returns a new string where the case of each letter is switched.
capitalize ( )
Returns a new string where the first letter is capitalized and the rest are lowercase.
title ( )
Returns a new string where the first letter of each word is capitalized and all others are lowercase.
strip ( )
Returns a string where all the white space (tabs, spaces, and newlines) at the beginning and end are removed.
replace(old, new [,max])
Returns a string where occurrences of the string ‘old’ are replaced with the string ‘new’. The optional ‘max’ limits the number of replacements.
*=
x *= 5 is equivalent to x = x * 5
/=
x /= 5 is equivalent to x = x / 5
%=
x %= 5 is equivalent to x = x % 5
+=
x += 5 is equivalent to x = x + 5
-=
x -= is equivalent to x = x - 5
==
equal to
!=
not equal to
>
greater than
<
less than
> =
greater than or equal to
<=
less than or equal to
append(value)
adds the value to the end of a list
sort( )
Sorts the elements of a list. Smallest value first. Optionally you can pass a Boolean value to the parameter ‘reverse’. If you pass True, the list will be sorted with the largest value first. ex: sort(reverse=True)
reverse( )
Reverses the order of a list
count(value)
Returns the number of occurrences of ‘value’
index(value)
Returns the first position number of where ‘value’ occurs
insert( i, value)
inserts ‘value’ at position ‘i’
pop([i])
Returns value at position ‘i’ and removes value from the list. Providing the position number ‘i’ is optional. Without it, the last element in the list is removed and returned
remove(value)
Removes the first occurrence of ‘value’ from the list
del list[position:range]
Deletes a value or range of values based on their position number
get(key, [default])
Returns the value of “key”. If key doesn’t exist, then the optional “default” is returned. If “key “ doesn’t exist and “default” isn’t specified, then None is returned.
keys( )
Returns a view of all the keys in a dictionary.
values( )
Returns a view of all the values in a dictionary.
items( )
Returns a view of all the items in a dictionary. Each item is a two-element tuple, where the first element is a key and the second element is the key’s value.