forked from adaptives/python-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_sequences.py
More file actions
executable file
·16 lines (12 loc) · 633 Bytes
/
python_sequences.py
File metadata and controls
executable file
·16 lines (12 loc) · 633 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/usr/bin/python
#Note: lists, tuples, and strings are all sequences in Python. Sequences allow
#indexing and slicing operations
#When a sequence is sliced the resulting object is a brand new object
jvm_langs = ['Java', 'Jython', 'Groovy', 'JRuby', 'Scala', 'Clojure']
print 'The first JVM language was ', jvm_langs[0]
#Let's slice the list. Slicing can be done with positive and negative indexes
print 'The second and third JVM languages are ', jvm_langs[1:3]
print 'The last 2 JVM languages are ', jvm_langs[-2:]
print 'The first 2 JVM languages are ', jvm_langs[:2]
name = 'Parag Shah'
print 'The first name is ', name[0:5]