Methods Flashcards

1
Q

String.upper()

A

Makes the first letter upper case

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

Method to append an element to the end of the list

A

list.append(element)

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

Set method

A

set() method is used to create a new set object. A set is an unordered collection of unique elements.

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

Ways to use set method

A
  • create a set from a list.
  • create a set from a dictionary. Converts only keys.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

A way to add element to a string

A

string += element

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

How to convert integer into a string

A

str(integer)

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

Method for lower case

A

string.lower()

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

replace method

A

Is a built in string method used to replace occurrences of a substring with a new string within a given string

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

Replace method syntax

A

string.replace(old_substring, new_substring, count)

count is optional. The max number of occurrences of old string to replace.

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

Ways to get rid of white space in a string

A
  • with string.replace() method. Removes all white spaces
  • string.strip() method - removes space at the beginning of a string and at the end
  • str.lstrip(), str.rstrip() - removes it from left or right side
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How to convert a list of strings into a string

A

With join method
str.join(lst)

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

How to convert a list with int to a string

A

With join() method
Example: lst =[…..]
str1= “ “.join([str(elem) for elem in lst])

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

How to turn a sentence into an array

A

sentence.split()
It can’t be combined with other methods

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

Length of an element

A

len(element)

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

Get the type of an element

A

type(element)
if type(element) == int:

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

How to reverse a string

A

element[::-1]

17
Q

Add element to a set

A

set.add(element)

18
Q

Check if an element in a set

A

element in mySet:
True/False

19
Q

Length of a set

A

len(mySet)

20
Q

Remove a specific element from a set

A

mySet.discard(element)

21
Q

How to add an element to a dictionary of lists

A

dictionary[key_of_a_list].append(element)

22
Q

Example of enumerate function use

A

Add