Input And Output Flashcards
Conversion specifiers
Tells Python how to render the corresponding value .
Specifiers Meaning
d integer
o Octal (base 8) value
x Lowercase hexadecimal (base 16)
X Uppercase hexadecimal
e Lowercase float hexadecimal
E Uppercase float hexadecimal
F Float
s String
% % character
Conversion specifiers example
What does this output?
> > > a, b, c = ‘cat’, 3.14, 6
> > > s = ‘There's %d %ss older than %.2f years ‘ % (c, a, b)
> > > s
“There’s 6 cats older than 3.14 years “
String formatting
format string function
format(value, format_spec)
Use “{ }” curly brackets, anything within them is replaced
“Named replacement “
Replacement by position- use 0, 1 etc
A _______ is a named collection of bits stored on a secondary storage device such as a hard disk, USB drive, flash memory stick, eyc.
File
What are the two categories of files?
Text files and binary files
Text file characteristics
Essentially “strings on disk”
Can be edited with any text editor
Can be difficult for programs to read
Larger than binary files
Binary file characteristics
Not human readable
Take up less space
Easier for programs to use
________ are used to store files
Folders or directories
Hierarchical folder structure
A pathname is used to identify a file or folder.
Windows pathnames use a “" backslash
Mac and Linux systems use “/” forward slash
cwd
current working directory
The one directory that has been designated as the default directory.
os.getcwd()
File and folder functions
Returns the name of the current working directory
os.listdir(p)
File and folder functions
Returns a list of strings of the names of all the files and folders in the folder specified by the path p.
os.chdir(p)
File and folder functions
Sets the current working directory to be path p.
os.path.isfile(p)
File and folder functions
Returns True just when path p specifies the name of a file, and False otherwise
os.path.isdir(p)
Returns True just when path p specifies the name of a folder, and False otherwise
os.stat(fname)
File and folder functions
Returns information about fname, such as its size in bytes and the last modification time