cs 14.1-4

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

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

+ and +=

Like arrays, the first index of a string is ___________

0 and the last index is the length minus 1

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

25

What is a string literal?

A set of characters delimited with quotations

What is a string?

A set of characters that behaves as a single unit

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

A variable stores one string value; therefore, it is an example of a simple data type

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

A variable stores several character values; therefore, it is an example of a data structure

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

ANG RANGE OR

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

Capital letters have smaller code values; String values cannot be compared properly when one starts with a lowercase letter and the other with a capital.

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

False

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

Find starts at the beginning of the string and searches forwards, while rfind stars at the end of the string and searches backwards

Look at program StringCommands10.py and its output and refer back to question #15. Explain how this program fixes the issue from program StringOperators07.py.

It uses the upper command to convert apple to APPLE to have it properly compared

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

Multiline comments

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

Multiple sections of the string on separate lines with + & \, multiple sections of the string can be combined with parentheses

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 isolating a substring, do you get an error if either of the numbers is too large?

No, the substring will just go to the end of the string

Look at program StringCommands06.py, specifically at lines 10 and 11. Do these lines of code alter the value of the original string s1?

No, they return an altered copy of the original

Assume string q has a length of 10. What would be the output of print(q[11]) ?

Run-time error with index out of range message

isprintable

The entire string contains any of the characters that you can type. Also could be an empty string.

istitle

The first letter of every word in the string is capitalized. The rest are lowercase.

What is concatenation?

The joining together of two or more strings

Refer to your answer to the previous question. Why are these called overloaded operators?

They can perform more than one job (as in mathematical addition and string concatenation)

What happens if you try to convert "2.71828" to an integer or "Hello World" to a real number?

This would be a run-time error

What operator is used to define a multiline string literal?

Triple-double quote (""")

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 large sets of symbols for a variety of purposes

Give a couple examples of something that involves String Processing.

Word processing term papers, sending emails, and responding to online surveys

Can a multiline string literal be stored in a variable?

Yes

Look at program StringCommands07.py, specifically at lines 7 and 10. Do these lines of code alter the value of the original string s1?

Yes because they make s1 = the altered version of itself

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?

Yes, len returns the number of characters in a string

Explain how to display a string in reverse order.

You count from the last index (n-1) to the first index (0) backwards (n-1,-1,-1) s = "computer", n = len(s), and r = "" for k in range(n-1,-1,-1): r += s[k] print(r) retupmoc

isupper

all letters in the string are UPPERCASE

islower

all letters in the string are lowercase

split command

breaks a sentence into words

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

city is the string variable and "Dallas" is the string literal

isdecimal

entire string contains 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

isdigit

entire string contains 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ¹, ², ³

isnumeric

entire string contains 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ¹, ², ³, ¼, ½, ¾

isspace

entire string contains invisible characters like space, tab or new line

isalpha

entire string contains letters

isalnum

entire string contains letters or 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

isidentifier

entire string contains letters or 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 or _ and starts with a letter

What command will convert strings to real numbers?

float

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

greeting = "Hello" * 100

What command will convert strings to integers?

int

In Python, arrays and strings can only be multiplied by __________ values.

integer

If your string has a mixture of CAPITAL letters, lowercase letters, digits, and symbols, the upper function will only affect the _____________ ____________ in the string. Likewise, the lower function will only affect the ______________ ____________ in the string.

lowercase letters; uppercase letters

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

print(fruit[4])

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

str

Refer to the previous question. Would it have worked if the lower function was used instead?

yes

Can strings be traversed, like arrays?

yes with the for loop


Set pelajaran terkait

New Jersey Laws, Rules and Regulations Common to all Lines

View Set

Chapter 9 Intermediate Financial 1

View Set

Starting Out With Visual C# Chapter 2 Checkpoint Questions 2.45-2.48

View Set

(C1W1): Foundations of User Experience (UX) Design - Weekly challenge 1: The basics of user experience design

View Set

anatomy 2 pearson chapter 18 cardiovascular heart

View Set

APES 5.11 - Ecological Footprint

View Set

NUR 2120 Exam #2 Practice Questions

View Set

سعة فضل الله تعالى

View Set

Point-Slope Form and Linear Equations Unit Test Review, Algebra, Unit Test Review, Unit Test Review

View Set