What does the replace() command do?
It replaces all occurrences of a specified substring in a string.
What is the result of len('Boston 4 ever')?
13.
1/92
p.13
Finding and Replacing Substrings

What does the replace() command do?

It replaces all occurrences of a specified substring in a string.

p.8
String Length and Character Count

What is the result of len('Boston 4 ever')?

13.

p.18
Tuples as Data Sequences

What happens when you add two tuples?

They are concatenated.

p.2
Distance Conversion

If you have 5 miles, how many kilometers does that equal?

Approximately 8.04672 km.

p.17
Tuples as Data Sequences

What does (3, 5, '7', '9')[1] evaluate to?

5.

p.9
String Case Conversion Methods

What is the output of 'Ups AND Downs'.upper()?

'UPS AND DOWNS'.

p.19
Tuples as Data Sequences

What is required for swapping values using tuples?

The variables must be elements of the tuple.

p.5
String Data Type in Python

What type of object is created when using num_one = 'one'?

An object of type str with the value 'one'.

p.24
User Interaction with Input

What is the purpose of storing input in a variable?

To hold data that can be used later in the program.

p.22
User Interaction with Input

What should be included in the parentheses of the input() command?

A string object that represents the prompt for the user.

p.14
Mathematical Operations on Strings

What is the result of adding the strings 'one' and 'two'?

'onetwo'.

p.16
Tuples as Data Sequences

What does the len() function do when used on a tuple?

It returns the number of objects inside the tuple.

p.4
String Data Type in Python

What does an empty string look like in double quotes?

"".

p.15
Tuples as Data Sequences

What does the tuple (1, "2", False) contain?

An integer, a string, and a Boolean object.

p.20
User Interaction with Input

Can you print multiple expressions in one print statement?

Yes, by separating them with commas, e.g., print('Value:', value).

p.13
Finding and Replacing Substrings

What is the result of the command 'variables have no spaces'.replace(' ', '_')?

'variables_have_no_spaces'.

p.5
String Data Type in Python

What does the statement num_two = '2' create?

An object of type str with the value '2'.

p.17
Tuples as Data Sequences

How do you index into a tuple?

You use the [] operator, similar to indexing into a string.

p.24
User Interaction with Input

What is an example of storing input in a variable?

name = input('Enter your name: ')

p.14
Mathematical Operations on Strings

What is concatenation in the context of strings?

Addition of two string objects.

p.7
String Indexing and Slicing

What is an example of a substring from the string s = 'snap crackle pop'?

'snap'.

p.21
User Interaction with Input

What is the default separator used by the print() function in Python?

A space.

p.15
Tuples as Data Sequences

How is a singleton tuple represented in Python?

(5,)

p.22
User Interaction with Input

What command is used to get input from the user in Python?

The input() command.

p.1
User Interaction with Input

Who is the instructor for the session?

Dr. Liang Zhao.

p.6
String Indexing and Slicing

What does the expression 'Python rules!'[7] evaluate to?

'r'.

p.12
Finding and Replacing Substrings

Can the count() method be used to count overlapping substrings?

No, it counts only non-overlapping occurrences.

p.17
Tuples as Data Sequences

What does (3, (3, 5), '7', '9')[1] evaluate to?

(3, 5).

p.15
Tuples as Data Sequences

What is a tuple in Python?

A data type that represents a sequence of any objects.

p.4
String Data Type in Python

Can a string in Python contain numbers?

Yes, for example, "525600".

p.15
Tuples as Data Sequences

What does the tuple (5, (6, 7)) contain?

An integer and another tuple made up of two integers.

p.2
Temperature Conversion

What formula is used to convert Fahrenheit to Celsius?

c = (f - 32) / 1.8

p.2
Distance Conversion

How do you convert miles to kilometers?

km = miles / 0.62137

p.2
Distance Conversion

What is the conversion from kilometers to meters?

meters = 1000 * km

p.17
Tuples as Data Sequences

What is the index of the first object in a tuple?

0.

p.4
String Data Type in Python

Give an example of a simple string object.

"simple".

p.16
Tuples as Data Sequences

What is the result of len((3, 5, '7', '9'))?

4, because the tuple has four elements.

p.9
String Case Conversion Methods

What is the output of 'Ups AND Downs'.swapcase()?

'uPS and dOWNS'.

p.13
Finding and Replacing Substrings

Does the replace() command replace only the first occurrence of a substring?

No, it replaces all occurrences.

p.8
String Length and Character Count

If a = 'eh?', what does len(a) evaluate to?

3.

p.18
Tuples as Data Sequences

What is the result of adding the tuples (1, 2) and (-1, -2)?

(1, 2, -1, -2).

p.2
Distance Conversion

What is the output format for converting 5 miles?

miles 5 km 8.04672 meters 8046.7

p.9
String Case Conversion Methods

What does the capitalize() method do?

It converts the first character to uppercase and the rest to lowercase.

p.8
String Length and Character Count

What does len('') evaluate to?

0.

p.5
String Data Type in Python

Why is '2' considered a string in the context of num_two?

'2' is a string and not the integer 2.

p.10
Finding and Replacing Substrings

What can you search for using the find() command?

A particular substring inside a larger string.

p.18
Tuples as Data Sequences

What is the result of multiplying the tuple (1, 2) by 3?

(1, 2, 1, 2, 1, 2).

p.21
User Interaction with Input

Can you print different data types together in Python?

Yes, Python allows printing different data types together using the print() function.

p.9
String Case Conversion Methods

What is the output of 'Ups AND Downs'.lower()?

'ups and downs'.

p.9
String Case Conversion Methods

What does the swapcase() method do?

It converts lowercase letters to uppercase and vice versa.

p.20
User Interaction with Input

How do you print a simple string in Python?

Using the print() function, e.g., print('Hello, World!').

p.19
Tuples as Data Sequences

What can you use tuples for regarding variable names?

To swap the object values associated with variable names.

p.1
User Interaction with Input

What are the main topics covered in Session 3 of ISEM 2006?

Strings, Tuples, and Interacting with The User.

p.24
User Interaction with Input

How do you store user input in a variable in Python?

By using the input() function and assigning it to a variable.

p.4
String Data Type in Python

What is the type of a string in Python?

str.

p.12
Finding and Replacing Substrings

What parameters can be passed to the count() method?

Optional start and end parameters to specify a substring search range.

p.9
String Case Conversion Methods

What does the lower() method do in Python?

It converts all letters in the string to lowercase.

p.15
Tuples as Data Sequences

What type of objects does the tuple ("a", "b", "cde", "fg", "h") contain?

Five string objects.

p.1
User Interaction with Input

Who edited the session on Programming for Business Applications Using Python?

Dr. Tony WONG.

p.6
String Indexing and Slicing

What does the expression 'Python rules!'[0] evaluate to?

'P'.

p.12
Finding and Replacing Substrings

What is the syntax for using the count() method?

string.count(substring)

p.21
User Interaction with Input

How can you print multiple objects in Python?

By using the print() function with commas to separate the objects.

p.4
String Data Type in Python

What is an example of a string with spaces and special characters?

"a long string with Spaces and special sym&@L5_!".

p.20
User Interaction with Input

What is the purpose of printing expressions in Python?

To display output to the user.

p.11
Finding and Replacing Substrings

What does the expression '"a" in "abc"' evaluate to?

True, because the substring 'a' is in the string 'abc'.

p.10
Finding and Replacing Substrings

What command is used to find a specific substring in a string?

The find() command.

p.22
User Interaction with Input

How do you prompt the user to input their name using input()?

By placing a string object in the parentheses of input(), like input('Enter your name:').

p.14
Mathematical Operations on Strings

What are the two mathematical operations that can be performed on string objects?

Addition (concatenation) and multiplication (repetition).

p.6
String Indexing and Slicing

What is the most basic operation you can do with a string object?

Indexing into a string.

p.21
User Interaction with Input

What will happen if you print multiple objects without commas in Python?

It will result in a TypeError because Python will not know how to concatenate them.

p.16
Tuples as Data Sequences

What type of data can be included in a tuple?

Tuples can include various data types, such as integers and strings.

p.15
Tuples as Data Sequences

How is an empty tuple represented in Python?

()

p.13
Finding and Replacing Substrings

What are the two items you need to provide in the parentheses for replace()?

The substring to find and the substring replacement, separated by a comma.

p.6
String Indexing and Slicing

What is indexing into a string?

Determining the value of a character at a certain position in the string.

p.12
Finding and Replacing Substrings

What method is used to count the occurrences of a substring in a string in Python?

The count() method.

p.21
User Interaction with Input

What is the purpose of printing multiple objects in programming?

To display information or results from various variables or data structures at once.

p.24
User Interaction with Input

Can you store different types of input in a variable?

Yes, input can be stored as strings, integers, or other data types depending on conversion.

p.14
Mathematical Operations on Strings

What does multiplication of a string by an integer represent?

Repetition of the string.

p.15
Tuples as Data Sequences

What does the tuple (1, 2, 3) contain?

Three integer objects.

p.9
String Case Conversion Methods

What is the output of 'a long Time Ago...'.capitalize()?

'A long time ago...'.

p.20
User Interaction with Input

How can you format strings when printing in Python?

Using f-strings or the format() method.

p.11
Finding and Replacing Substrings

How can you check if a substring is in a string in Python?

By using the keyword 'in'.

p.2
Temperature Conversion

If the temperature in Fahrenheit is 75, what is the Celsius equivalent?

Celsius value is approximately 23.89.

p.10
Finding and Replacing Substrings

What type of search does the find() command perform?

A case-sensitive search.

p.10
Finding and Replacing Substrings

In what scenarios might you use the find() command?

To check if a specific file exists or to search for a word in a text document.

p.18
Tuples as Data Sequences

How can you repeat a tuple multiple times?

By multiplying it by an integer.

p.7
String Indexing and Slicing

What is the process of extracting data from a string called?

Getting a substring of the string.

p.14
Mathematical Operations on Strings

What is the result of multiplying the string 'a' by 3?

'aaa'.

p.4
String Data Type in Python

What does an empty string look like in single quotes?

''.

p.9
String Case Conversion Methods

What does the upper() method do in Python?

It converts all letters in the string to uppercase.

p.15
Tuples as Data Sequences

Why is there an extra comma in the singleton tuple (5,)?

To indicate that it is a singleton tuple and not for mathematical precedence.

p.20
User Interaction with Input

What happens if you try to print a variable that hasn't been defined?

It will raise a NameError.

Study Smarter, Not Harder
Study Smarter, Not Harder