DevNet Associate DEVASC 200-901 Official Certification Guide by Adrian Iliesiu (z-lib.org)

(andrew) #1
str.replace(old,
new[, count])

Replace characters in the string

str.lower() Make the string all lowercase

str.rstrip([chars
])

Strip whitespace characters from the
front of the string

str.strip([chars]) Remove whitespace characters from
the beginning and end of the string

str.upper() Make the string all uppercase

Lists


Python, unlike other programming languages, such as
C++ and Java, doesn’t have arrays. If you want to store a
bunch of values, you can use a list. You can use a variable
to store a collection of items in a list. To create a list, you
assign the contents of the list to a variable with the = and
[] and separate the items with commas, as in this
example:


Click here to view code image


>>> kids = ['Caleb', 'Sydney', 'Savannah']
>>> kids
['Caleb', 'Sydney', 'Savannah']

A list can contain any Python object, such as integers,
strings, and even other lists. A list can also be empty and
is often initialized in an empty state for programs that
pull data from other sources. To initialize a list in an
empty state, you just assign two brackets with nothing in
them or you can use the built-in list() function:


emptylist = []
emptylist2 = list()
Free download pdf