Comp lecture 3 - Strings Flashcards

0
Q

What does he ‘len’ function do?

A

Counts the number of characters in the string

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

String literal syntax

A

Strings need to be surrounded by quotes

Consistency - if u start with single quotes u should continue with single quotes likewise for double quotes

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

What is character code ? What are the different types of character codes?

A

Each character in the string or of the character that we press on the keyboard is represented by a unique number used by the computer to convert the character to binary.
There are two types of character codes : ASCII and Unicode
ASCII = American Standard Code for Information Interchange, has limited characters (256), used widely
Unicode = has 100,000 characters

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

What is an ord function? How is it different from chr function?

A
Ord = enter a character and it will give the ASCII of that character
Chr = enter the ASCII and it will give the character
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Important note about escape notations

A

They are interpreted only in print statements

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

What is appending in Python

A

Adding strings to each other

Eg: ‘jake’ + ‘has a’ + ‘dog’

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

Reversing index starts from?

A

-1

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

What would the output of “Python” [1:5] be?

A

‘ytho’

Therefore 5 is exclusive

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

What would the output of. “Python” [:5] be?

A

‘Pytho’

Empty is considered 0 by default

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

What would the output for “Python” [1:] be?

A

‘ython’

Empty at the end = last value taken by default

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

“Python” [1:5:2]

A

2 = take every second character

‘yh’

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

“Python” [4:0:-1]

A

‘ohty’

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

Reverse “Python”

A

“Python” [::1]

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

Indexing

A

Every character in the string can be accessed using an integer index value

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

Slicing

A

Taking out a set desired characters from the string

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