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

Python Dictionaries

Python Dictionaries:

Functions:

 dict is a function, which is used to construct dictionaries from other mappings.

Methods:

1. clear
2. copy
3. fromkeys
4. get
5. has_key
6. items and iteritems
7. pop
8. popitem
9. setdefault
10.update
11. values and itervalues