titbits from official tutorial Flashcards
how do you get print to treat inputs as raw characters
use r e.g. print (r ‘c:\windows\files’)
substring extraction; in str[a:b] what is included and what is exculded?
a is included and b is excluded.
name mutable objects in python
list, sets, dictionaries
name some immutable objects in python
tuple, string, number
simplest way to print a sequence of numbers
range (start, stop, step)
by default python source code files are encoded as —-?
UTF8
how to ensure a newline is NOT entered aftr the print?
use keyword end
how to ensure a specific character (e.g.a comma) is entered after a print?
print(a, end=’,’)
whats the difference between a set of statements enclosed by an else and followed by a for loop and a set of statements followed by a for loop (without the else)
If the loop has a break statement and it was exited through execution of that break as opposed to natural exhaustion of the sequence it was iterating over, then the statement in else block WILL NOT be executed whereas a block not enclosed by else WILL BE executed.
syntax for a lambda function
lambda variable: expression involving variable and parameter
what are 2 conditions under which python does not check for compiled modules
- if the module is run from the python command line
2. if there is no source module, i.e, only the compiled code exists in the current directory
what would you put in __init__.py file in a package
- the list of symbols imported if import * is used.
2. any other initialization code.
what is hr equivalent of pritnf(%d) command in python?
print(‘Hello {}”.format(variable_name))
what are 2 modes in which you can open files in python?
text and binary mode.
what are the two formats your data must be in to write to a file?
string or bytes