2nd Semester Intro to Computer Science

Do Now 2.05

Part 1 - Open up the console

Type the following example code using interactive mode

Example 1

 >>> a = [123, 'First Item', 456, 'Second Item']
 >>> b = a[0:2]
 >>> print(a)
 >>> print(b)

In your notebook

Respond to the following

  1. What happens to a?
  2. What is b?
  3. What type is b?

Example 2

 >>> a = [123, 'First Item', 456]
 >>> a.remove('First Item')
 >>> print(a)

Continue in your notebook

Respond to the following questions

  1. What does remove do?
  2. What would the length of this list be after remove?

Example 3

 >>> a = [123, 'First Item', 456]
 >>> a.pop()
 >>> print(a)

Continue your responses in your notebook

  1. what does pop do?
  2. What is the difference between remove and pop?

Example 4

 >>> a = [123, 'First Item', 456, 'Second Item']
 >>> b = a + ['Third Item']
 >>> print(a)
 >>> print(b)

Continue your responses to the following in your notebook

  1. What happens to a?
  2. What is b?
  3. What type is b?

Example 5


 >>> a = []
 >>> print(len(a))
 >>> a.append('First Item')
 >>> print(a)

In your Notebook

  1. What was the length of []?
  2. What does append do? What would the length be after append?

Edit this page Report an issue