Strings Flashcards

1
Q

What programs use string to perform operations?

A

search engines, emails

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

How to iterate over a string= “AMANDA”

A

for count in string:

print count

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

How can you access individual characters with a string?

A

via index

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

Indexing starts at ?

A

0

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

provide an example of index

A

name = “Sakura”
name[2]
k

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

Negative numbers in index starts with?

example

A

-1
for instance: name =”Sakura”
name[-1] = “a”
name[-2] =”r”

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

what error does this give?
name =”AVA”
name[4]

A

IndexError Exception

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

How do you find the length of a string?

name = “Sakura”

A

len(name)

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

How do you concatinate two or more strings?

A

use the + operator

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

You can also use what to concatinate? Demonstrate

A
\+=
a ="av"
a+="a"
print (a)
ava
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Strings are mutable or immutable. Why?

A
Immutable. Cannot be changed.
a= "a"
a += "va"
in the memory its
a
ava
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Can you do this? Why? Why not?
name =”ava”
name[0] =”f”

A

No cause strings are immutable.

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

What is slicing used for?

A

to select a range of characters from a string

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

String slices are also called

A

substrings

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

Syntax for slicing

A

string [start:end]

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

How to find strings

A

With in or not in operators

17
Q

whitespaces are :

A

\n , \t and space

18
Q

testing alphanumeric

A

isalnum()

19
Q

testing alphabets

A

isalpha()

20
Q

testing lower

A

islower()

21
Q

testing upper

A

isupper()

22
Q

testing digits only

A

isdigit()

23
Q

tessting whitespaces

A

isspace()

24
Q

Write syntax for finding:

end, start, find,replace

A

endswith(substring)
find(substring)
startswith(substring)
replace(old,new)

25
Q

How to make repetition in a string

A

string = “an”

string * 4

26
Q

String =”one two”

How to split them?

A

String.split()

27
Q

By default what is the separater?

A

space

28
Q

What if you need to separate this?

name =”any/who/out”

A

name.split(‘/’)