comp sci chapter 14

¡Supera tus tareas y exámenes ahora con Quizwiz!

Which 2 operators can be used for mathematical addition and string concatenation?

+ and +=

Suppose you have a really, really long string literal. List 2 ways make the entire string literal visible on the computer screen.

-Divide string into two halves and concatenate them together -List the different parts of the string in parenthesis

Like arrays, the first index of a string is

0

What is the constant mathematical difference between the ASCII value of a lowercase letter and its corresponding CAPITAL letter?

32

If a string has a length of 40 characters, what is its last index?

39.

What is the output of this program? s1 = "HOW MANY BANANAS ARE ON ANA'S BANANA BOAT" print(s1.count("NA")) s2 = s1[9:36] print(s2.startswith("BANANA")) print(s2.endswith("BANANA"))

5 true true

What is the output of this program statement? print(ord('C'), chr(68))

67 D

What is a string?

A String is a set of characters that behaves as a single unit.

What is a string literal?

A string literal is a set of characters delimited with double quotations.

Look at program StringOperators07.py and its outputs. Explain why the 4th output says "apple goes alphabetically before ZEBRA".

Because it is mixed with capital and lowercase letters

Look at the program StringCommands02.py and its output. Both strings seem to be storing the exact same multiline string literal. Why do they have different lengths?

Because one string had many spaces in it while the other used more enter commands

Consider this statement: city = "Rockwall" What is the string variable and what is the string literal?

City is the string variable. "Dallas" is the string literal.

What is the output of print("Apples" == "Oranges") ?

False.

What is concatenation?

Joining 2 or more strings together.

Refer to the previous question. What would be the output of this program segment? print(fruit[3:5]) print(fruit[2:]) print(fruit[:4])

NG ANGE ORAN

Explain how to display a string in reverse order.

Strings can be reversed using slicing. To reverse a string, we simply create a slice that starts with the length of the string, and ends at index 0. The slice statement means start at string length, end at position 0, move with step -1 (or one step backward). Or we can use the reverse command.

In the previous chapter, you learned that the len function returns the number of items in an array. Does len work with strings? If so, what does it return?

Tells you how many characters are in the string

What is the output of print("Apples" == "Apples") ?

True.

The characters in a string include 4 things. List them.

Upper-case letters, lower-case letters, numerical digits and symbols.

Give a couple examples of something that involves String Processing.

Word processing term papers, writing memoirs, sending email messages, responding to surveys, placing online orders and registering products.

Why is using find and rfind preferable to using index and rindex?

because the the other 2 commands crash when the substring is not found

What command will convert strings to real numbers?

float

Consider this statement: fruit = "ORANGE" Write the code necessary to display the 'N'.

fruit = "ORANGE" print() print(fruit[3])

Suppose, for whatever reason, you wanted a string that contains the word "Hello" 500 times. Write the code that will generate this string, called greeting, using the word "Hello" only once.

greeting = Hello print(greeting * 500)

What command will convert strings to integers?

int

In Python, arrays and strings can only be multiplied by what kind of values.

integer values

What command is the opposite of the split command?

join

If your string has a mixture of CAPITAL letters, lowercase letters, digits, and symbols, the upper function will only affect the __________ in the string. In a similar manner, the lower function will only affect the __________ in the string.

lowercase letters uppercase letters

Refer to your answer to the previous question. For quite some time, we have used this same operator for what

mulit-line comments

In the previous chapter, you learned that the reverse function will "reverse" the order of items in an array. Does reverse work with strings?

no

When performing string slicing, do you get an error if either of the numbers is too large?

no

is it possible to use the float command to convert the string value in to a real number

no

is it possible to use the int command to convert the string value in to an integer

no

do the string commands alter the original string at all

no instead, they create an altered copy of the string

The split command essentially breaks a _________ into an array of ___________.

sentence words

What command will convert integers, real numbers and Boolean values to strings?

str function

Write a statement that supports the argument that "a string is a simple data type."

title = "Exposure Computer Science" title stores one string value

Write a statement that supports the argument that "a string is a data structure."

title = "Exposure Computer Science" title stores several character values

what does float do

to convert real numbers or integers into floating point numbers

What operator is used to define a multiline string literal?

triple quotes

When working with strings, what is the difference between functions find and rfind?

when find searches for a substring, it starts at the beginning of the string and searches forward, while rfind starts at the end of the string and searches backward

Can a multiline string literal be stored in a variable?

yes

Can strings be traversed, like arrays?

yes


Conjuntos de estudio relacionados

Cool - workbook-unit 2- Harry Potter's Best Friend ( by Gili Yarkoni)

View Set

Computer Science IB SL Definitions OOP

View Set

Ch 1. Fundamentals of Reading Comprehension

View Set

Unit 15 Volume of Rectangular Prisms (composite shapes) (fractional dimensions)

View Set