Strings Flashcards

1
Q

Write a brief description of strings in Python.

A

Strings are used to record text information. They can be used with double or single quotations and are immutable

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

Write a one word string

A

‘hello’

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

Write a phase in a string

A

"”hello world this is a string”

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

‘I’m using single quotes but I will still get an error’
Explain why an error will occur.

A

An error will ouccur because there is a single quote in What’s stopped the string. Using single and quote combinations will get the complete statement.
“I’m now able use single quotes inside a string”

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

How do you output multiple strings?

A

Use a print statement to print a string.
print(‘hello world’)
print(hello world 2’)

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

What function is used to check the length of a string

A

len()

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

s = ‘Hello World’
What element is:
s[0]

A

‘H’

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

s = ‘Hello World’
What element is:
s[4]

A

‘o’

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

s = ‘Hello World’
output - s[1:]

A

s[1:] ‘ ello World’

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

s = ‘Hello World’
output s[:3]

A

‘Hel’

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

s = ‘Hello World’
Grab everything

A

s[:]

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

s = ‘Hello World’
output [:-1]

A

‘d’

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

s = ‘Hello World’
Grab everything in steps size 2

A

s[::2] ‘HloWrd’

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

s = ‘Hello World’
output - s[::-1]

A

‘dlroW olleH’

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

Strings are Immutable True or False?

A

True

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

s = ‘Hello ‘World’
concatenate this string

A

s = s + ‘concatenate me’
print(s)
Hello World concatenate me

17
Q

letter = ‘z’
letter*10 =

A

‘zzzzzzzzzz’

18
Q

What method us used to split a string by blank space?

A

s.split()

19
Q

What does it mean to concatenate in Python

A

Concatenate means to add a new string that contains the original string

20
Q

‘2’ + ‘3’
output

A

23

21
Q

x = ‘This is a string’
x.split()
output -

A

[‘This’, ‘is’, ‘a’, ‘string’]

22
Q

x = ‘This is a string’
x.split(‘s’)
output -

A

[‘Thi’, ‘i’, ‘a’ ‘tring’]

23
Q

mystring = ‘hello world’
mystring[-3]
output -

A

‘r’

24
Q

mystring = ‘fabrication’
mystring[2:]
output -

A

‘brication’

25
Q

mystring = ‘tomatoes’
mystring[:3]

A

‘tom’

26
Q

mystring = ‘trainers’
mystring[3:6]

A

‘ine’

27
Q

mystring= ‘fabrication’
mystring[::]

A

‘fabrication’

28
Q

mystring= ‘quantifiers’
mystring[::5]

A

‘qis’

29
Q

mystring = ‘abcdefghijk’
mystring[2:7:2]

A

‘ceg’