Comp lecture 3 - Strings Flashcards
What does he ‘len’ function do?
Counts the number of characters in the string
String literal syntax
Strings need to be surrounded by quotes
Consistency - if u start with single quotes u should continue with single quotes likewise for double quotes
What is character code ? What are the different types of character codes?
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
What is an ord function? How is it different from chr function?
Ord = enter a character and it will give the ASCII of that character Chr = enter the ASCII and it will give the character
Important note about escape notations
They are interpreted only in print statements
What is appending in Python
Adding strings to each other
Eg: ‘jake’ + ‘has a’ + ‘dog’
Reversing index starts from?
-1
What would the output of “Python” [1:5] be?
‘ytho’
Therefore 5 is exclusive
What would the output of. “Python” [:5] be?
‘Pytho’
Empty is considered 0 by default
What would the output for “Python” [1:] be?
‘ython’
Empty at the end = last value taken by default
“Python” [1:5:2]
2 = take every second character
‘yh’
“Python” [4:0:-1]
‘ohty’
Reverse “Python”
“Python” [::1]
Indexing
Every character in the string can be accessed using an integer index value
Slicing
Taking out a set desired characters from the string