- Sep 2020
-
greenteapress.com greenteapress.com
-
Lists
LISTS: • Sequence of values just like strings • Values in the list are called elements or items • A list can contain a list within itself and is called nested list • Lists are mutable • In operator can be used in the same way as strings Map: - it’s a function that acts onto each of the elements in a sequence Reduce:-an operation which combines sequence of characters into a single value Filter:-an operation which acts upon few elements of the list ***If two objects are identical they are also equivalent but if they are equivalent, they are not necessarily identical
-
Lists
LISTS: • Sequence of values just like strings • Values in the list are called elements or items • A list can contain a list within itself and is called nested list • Lists are mutable • In operator can be used in the same way as strings Map: - it’s a function that acts onto each of the elements in a sequence Reduce:-an operation which combines sequence of characters into a single value Filter:-an operation which acts upon few elements of the list *If two objects are identical they are also equivalent but if they are equivalent, they are not necessarily identical
-
Strings
STRINGS: • Sequence of characters • Index tells us which character in the sequence we want • Index must only be integers or else we will get Type Error • We can use the len() to get the length of the string • We can iterate through the strings in two different ways o for i in range(len(string): print(string[i]) o for i in string: print(i) • The in operator can be used to check whether a substring is present in the given string • Strings can be sliced and is Counterintuitive • Strings are immutable in nature
Tags
Annotators
URL
-