Python for Data Science, AI, and Development
This course has these modules…
This course has these modules…
Tuples are an ordered sequence
Here is a Tuple “Ratings”
Tuples are written as comma-separated elements within parentheses
Tuples concatenation is possible
Tuple slicing is also possible
Tuples are immutable
If one want to manipulate tuples, they have to create a new tuple with the desired values
Tuples nesting (tuple containing another tuple) is also possible
Ratings = (10, 9, 6, 5, 10, 8, 9, 6, 2)
Lists are also ordered in sequence
Here is a List “L”
L = ["Michael Jackson", 10.1, 1982]
A List is represented with square brackets
List is mutable
List can nest other lists and tuples
We can combine lists
List can be extended with extend()
method
append()
adds only one element to the List, if we append L.append([1,2,3,4])
, the List “L” will be:
L = ["Michael Jackson", 10.1, 1982,[1,2,3,4]]
The method split()
can convert the string into the List
"Hello, World!".split()
The split()
can be used with a delimiter we would like to split on as an argument
"A,B,C,D".split(",")
Multiple names referring to the same object is known as aliasing
You can convert a list into set
List = ['foo']
set(List)
To add elements to the set, set.add('foo')
To remove an element, set.remove(‘foo’)
To check if an element is present in the set:
'foo' in set
True/False
set1 & set2
or set1.intersection(set2)
Union of the sets, contain elements of both the sets combined, set1.union(set2)
To find the difference of sets:
#set1 difference from set2
set1.difference(set2)
#set2 difference from set 1
set2.difference(set1)