Tuesday, October 7, 2014

Python Basics: 2

Lists and Tuples

Indexing
a = "python"
a[0]
p

Slicing
a = "python"
a[1:] = list("erl")
perl

Memebership
a = ["Perl","Python"]
"Perl"  in a
True
"Ruby" in a
False

List is a Function and it is mutable (i.e You can change their contents)

1. Changing elements
2. Deleting elements

Methods in Lists:
1. append
2. count
3. extend
4. index
5. insert
6. pop
7.remove
8. reverse
9.sort



Tuples are sequences like Lists, But it cant be changed

No comments:

Post a Comment