pythonSC
Given the command shown on the lecture slide
What is
the prompt : $
the program name : uniq
the command-line argument mary.txt
What does the uniq program do?
filters out repeated lines in a file
What does the cat program do?
"concatenate and print files"
What does the grep program do?
print matched lines in the input file(s)
Is it possible that uniq and cat produce the same output? How?
Yes, when there are no repeated lines in a file.
Given the command shown on the lecture slide
What is the purpose of
class : the keyword you want to find in myfile.py
myfile.py : the file you want to find.
Given the command
What is the meaning of *.py?
find all file which filename end with .py
What does the following command do?
executing prog.py
What is a shbang in a Python program? Where is it placed inside a Python program?
#!, on 1st line to indicate interpreter
What does the command do:
change the prog.py's mod
What is the value of
Suppose you run the command
Inside the showargs.py program, suppose you have
What is the value of sys.argv?
What is the value of len(sys.argv)?
What is the value of sys.argv[1:]?
If the command $ python3 showargs.py hello world is used to run the Python program, what is printed by the statement
If the file mary.txt contains the following lines
what is the value of L after executing the following statements?
What is the purpose of end='' in the statement
end with nothing
Explain why
results in the integer value of 1, while
results in -1.
find will return the first index that you want to find in the iterable, and return -1 when target is not in iterable.
Rewrite the string literal "hello, I'm John." using
Rewrite the string literal 'she says, "This is great!" and left' using
Rewrite the string literal '\n means newline' using a raw string.
After executing the statement
What is the value of t?
What is the value of
Rewrite the following triple-quoted string literal using a non-triple-quoted string literal
on one single line
on three separate lines
Assume
How do you format the date using % formatting so that it appears as strings (expressed as string literals)
What is the value of
What is the meaning of 5e2? What is its data type?
5*10^2, float
What is the value of 5e-2?
5*10^-2
What is the value of '%c' % 100, given that ord('a') has the value of 97?
'd'
What is the format string S such that S.format(month, day, year)is equivalent to the traditional formatting of
What is the value of the expression
What is the format string S such that
evaluates to the string
What is the value of the expression
Rewrite the following expressions as f-string:
What is the value of the expression
Suppose you type the unix command wc (lightblue) and get the output (lightgreen) as shown below:
What are the meanings of 9, 32, and 249?
lineCount = 9
wordCount = 32
charCount = 249
What is the value of the expression
Assume you have
What is the value of