Skip to content

Instantly share code, notes, and snippets.

@thinkjson
Created April 13, 2015 12:02
Show Gist options
  • Select an option

  • Save thinkjson/ec5e23a3e39c9a26fd57 to your computer and use it in GitHub Desktop.

Select an option

Save thinkjson/ec5e23a3e39c9a26fd57 to your computer and use it in GitHub Desktop.
Intro to Programming Lesson 2
Python 2.7.8 (default, Apr 8 2015, 14:55:10)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> ["one","two","three"]
['one', 'two', 'three']
>>> ["one","two","three"][:2]
['one', 'two']
>>> ["one","two","three"][:-1]
['one', 'two']
>>> ["one","two","three"][-1]
'three'
>>> bucket = []
>>> bucket
[]
>>> bucket.append("candy")
>>> bucket.append(9)
>>> bucket.append("apple")
>>> bucket
['candy', 9, 'apple']
>>> bucket.insert(0, "spinach")
>>> bucket
['spinach', 'candy', 9, 'apple']
>>> bucket[2] = "crab"
>>> bucket
['spinach', 'candy', 'crab', 'apple']
>>> from speech import say
>>> for food in bucket:
... say("I like to eat %s" % food)
...
>>> bucket = ["apple","carrot","candy","crab"]
>>> bucket[2]
'candy'
>>> bucket[1]
'carrot'
>>> bucket + ["potato","corn"]
['apple', 'carrot', 'candy', 'crab', 'potato', 'corn']
>>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment