100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
CSC Exam 2 – Martin questions with complete solutions $15.99   Add to cart

Exam (elaborations)

CSC Exam 2 – Martin questions with complete solutions

 0 view  0 purchase
  • Course
  • CSC
  • Institution
  • CSC

CSC Exam 2 – Martin questions with complete solutions

Preview 2 out of 11  pages

  • November 16, 2024
  • 11
  • 2024/2025
  • Exam (elaborations)
  • Unknown
  • CSC
  • CSC
avatar-seller
BravelRadon
CSC Exam 2 – Martin questions with
complete solutions

Data Structure - correct answer ✔✔a compound unit that consists of several smaller pieces of data



"len" function - correct answer ✔✔Returns the number of characters it contains. It starts at zero on the
left then goes up by one to the right



>>> len("Hi there!")

9

>>> len("")

0



Immutable data structure - correct answer ✔✔it's internal data elements, the characters, can be
accessed, but the structure itself cannot be modified.



For loop - correct answer ✔✔can access any of the characters in a string.

treats an input file as a sequence of lines. on each pass through the loop, the loop's variable is bound to
a line of text read from the file.



>>> f= open("myfile.txt." ,'r')

>>> for line in f:

print(line)



First line.



Second line.

, Subscript operator - correct answer ✔✔Function that looks like '[]' . inspects each character at a given
position without visiting them all. The positions range from 0 to the length of the string minus 1. Also
used to add a new key/value pair to a dictionary or to replace a value associated with an existing key.



>>> name = 'Alan Turing'

>>> name[0] # Examine the first character

'A'

>>> name[3] # Examine the fourth character

'n'

>>> name[len(name)] # Oops! An index error!

Traceback (most recent call last):

File "<stdin>", line 1, in <module>

IndexError: string index out of range

>>> name[len(name) - 1 # Examine the last character

'g'

>>> name[-1] # Shorthand for the last one

'g'



slicing - correct answer ✔✔using a python subscript operator to obtain a sub-string



>>> name='myfile.txt'

>>>name[0:] # the entire string

'myfile.txt'

>>> name[0:1] # the first character

'm'

>>> name[0:2] # The first two characters

'my'

>>> name[:len(name)] # The entire string

'myfile.txt'

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller BravelRadon. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $15.99. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

75323 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$15.99
  • (0)
  Add to cart