Lecture 2 Flashcards

Mutable vs. non-mutable, string methods, tuples, string concatenation

1
Q

mutable objects definition

A

can be changed after they are created, like lists or dictionaries

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

immutable objects definition

A

cannot be changed after they are created, such as strings, integers, or tuples.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

string slicing definition

A

obtaining a sub-string from the given string by slicing it respectively from start to end

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

string slicing: array method. syntax

A

string_name[beginning:end:step]

*note that you can also index backwards in the steps parameter

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

how do you reverse a string?

A

stringname[::-1]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

slice() constructor (syntax and what it does)

A
  1. Returns a sliced object containing elements in the given range only.
  2. slice(stop)
    OR
    slice(start, stop, step)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

how do you slice a list?

A

listname[start, stop, step]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

count method for strings

A

stringname.count(“stringtosearch”)

returns number of occurrences of argument in stringname.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

what does the index method do when used on a string and what is the syntax?

A

stringname.index(“character”)

returns the index of the character in argument

NOTE that it will not work with strings, singular characters only!!!!!!!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

what does the split method do to a string and what is the syntax?

A

stringname.split(delimeter, max splits)

splits every item in the string, returns a list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

join method syntax and what it does

A

joiner.join(sequencetojoin)

joins every element in a sequence uisng the joiner. returns a string.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

isdigit and isalpha

syntax and use

A

check if argument passed is numerical or alphabetical, returns true or false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

tuple definition

A

An ordered collection or grouping of items.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

cna you type cast a list into a tuple and vice versa?

A

YES!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How do you access the elements in a tuple?

A

same way you do in a list, by indexing

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

what are the only 6 methods usable with tuples?

A

only the ones that reutn information, not the ones that modify the thing:

count, index, min, max, len, sum

17
Q

what does the find function do and what is the syntax?

A

This function is used to find the position of the substring within a string.It takes 3 arguments, substring , starting index( by default 0) and ending index( by default string length).

It returns “-1 “ if string is not found in given range.

It returns first occurrence of string if found.

find(“string”, beg, end)

18
Q

startswith and endswith methods

A

S.startswith(‘string2’), S.endswith(‘string2’): tests if string starts or ends with the given s