Menu

String Manipulation

Card 1 of 23 0 got it 0 still learning
Question
TapClick or press space to see the answer
Answer
All 23 cards in this set
What is meant by concatenation?
Joining two strings together to make one longer string
Which term describes taking part of a string between a start position and an end position?
Slicing
What is meant by an index?
The position of a character in a string
Which function returns the number of characters in a string?
len()
What does name.upper() produce?
A new string with all the letters changed to capitals
Which function converts a character into its ASCII code?
ord()
What is meant by a substring?
Part of a string, with its characters kept in order
What is meant by the code of a character?
The number that the character is stored as
In the string 'School', at which position is the letter 'h'?
2
How many characters are in the string 'Hi there!'?
9
The variable code holds the string 'ABCDEFGH'. What does code[2:5] give?
It gives CDE
The variable code holds the string 'GB2026LON'. Which slice gives the last three characters, LON?
It gives code[6:9]
A program runs print('4' + '5'). What happens?
It prints 45
The variable points holds the number 10. Which line prints Total: 10 without stopping with an error?
It runs print('Total: ' + str(points))
What does chr(ord('a') + 1) give?
B
Which line makes the variable name hold the uppercase version of its string?
It writes name = name.upper()
A username is built as surname[0:3].lower() + firstName[0:1].lower() + year[2:4], where year holds the text 2025. With surname Patel and firstName Sam, what is the username?
Pats25
A program reverses a word by looping through its characters, starting at the last position and finishing at the first. Why is result = result + word[i] written inside the loop?
To build the new string one character at a time
The variable word holds the string 'Python'. What does word[len(word) - 1] give?
N
The variable code holds the string 'GB2026LON'. Which slice gives the first two characters, GB?
code[:2]
A programmer needs the last four characters of a product code that may be different lengths. Why is code[len(code) - 4:] better than code[5:9]?
It works whatever the length of the code
A program asks the user to answer yes or no. Which condition accepts YES, Yes and yes?
if answer.lower() == 'yes'
A program loops through the characters of the word 'banana' and counts how many of them are vowels. What does it count?
3