Deck 8: More About Strings
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/37
العب
ملء الشاشة (f)
Deck 8: More About Strings
1
You cannot use a for loop to iterate over the characters in a string.
False
2
The strip()method returns a copy of the string with all the leading whitespace characters removed but does not remove trailing whitespace characters.
False
3
What is the first negative index in a string?
A) 0
B) -1
C) -0
D) the size of the string minus one
A) 0
B) -1
C) -0
D) the size of the string minus one
B
4
What are the valid indexes for the string 'New York'?
A) 0 through 7
B) 0 through 8
C) -1 through -8
D) -1 through 6
A) 0 through 7
B) 0 through 8
C) -1 through -8
D) -1 through 6
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
5
The index -1 identifies the last character of a string.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
6
What will be assigned to the variable s_string after the following code executes?
Special = '1357 Country Ln.'
S_string = special[ :4]
A) '7'
B) '1357'
C) 5
D) '7 Country Ln.'
Special = '1357 Country Ln.'
S_string = special[ :4]
A) '7'
B) '1357'
C) 5
D) '7 Country Ln.'
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
7
If the start index is __________ the end index,the slicing expression will return an empty string.
A) equal to
B) less than
C) greater than
D) less than or equal to
A) equal to
B) less than
C) greater than
D) less than or equal to
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
8
Indexing works with both strings and lists.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
9
What will be assigned to the variable some_nums after the following code executes?
Special = '0123456789'
Some_nums = special[0:10:2]
A) '0123456789'
B) '24682468'
C) '02468'
D) '02020202020202020202'
Special = '0123456789'
Some_nums = special[0:10:2]
A) '0123456789'
B) '24682468'
C) '02468'
D) '02020202020202020202'
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
10
When accessing each character in a string,such as for copying purposes,you would typically use a while loop.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
11
If a whole paragraph is included in a single string,the split()method can be used to obtain a list of the sentences in the paragraph.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
12
What will be displayed after the following code executes?
Mystr = 'yes'
Yourstr = 'no'
Mystr += yourstr * 2
Print(mystr)
A) yes + no * 2
B) yes + no yes + no
C) yesnono
D) yesnoyesno
Mystr = 'yes'
Yourstr = 'no'
Mystr += yourstr * 2
Print(mystr)
A) yes + no * 2
B) yes + no yes + no
C) yesnono
D) yesnoyesno
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
13
In slicing,if the end index specifies a position beyond the end of the string,Python will use the length of the string instead.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
14
The following expression is valid:
string[i] = 'i'
string[i] = 'i'
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
15
What will be assigned to the variable s_string after the following code executes?
Special = '1357 Country Ln.'
S_string = special[4:]
A) ' Country Ln.'
B) '1357'
C) 'Coun'
D) '57 C'
Special = '1357 Country Ln.'
S_string = special[4:]
A) ' Country Ln.'
B) '1357'
C) 'Coun'
D) '57 C'
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
16
What is the return value of the string method lstrip()?
A) the string with all whitespaces removed
B) the string with all leading whitespaces removed
C) the string with all leading tabs removed
D) the string with all leading spaces removed
A) the string with all whitespaces removed
B) the string with all leading whitespaces removed
C) the string with all leading tabs removed
D) the string with all leading spaces removed
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
17
If the + operator is used on strings,it produces a string that is a combination of the two strings used as its operands.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
18
Indexing of a string starts at 1 so the index of the first character is 1,the index of the second character is 2,and so forth.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
19
What will be assigned to the variable s_string after the following code executes?
Special = '1357 Country Ln.'
S_string = special[-3:]
A) '135'
B) '753'
C) 'Ln.'
D) 'y Ln'
Special = '1357 Country Ln.'
S_string = special[-3:]
A) '135'
B) '753'
C) 'Ln.'
D) 'y Ln'
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
20
The following code will display 'yes + no':
mystr = 'yes'
yourstr = 'no'
mystr += yourstr
print(mystr)
mystr = 'yes'
yourstr = 'no'
mystr += yourstr
print(mystr)
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
21
Which method would you use to determine whether a certain substring is present in a string?
A) endswith(substring)
B) find(substring)
C) replace(string, substring)
D) startswith(substring)
A) endswith(substring)
B) find(substring)
C) replace(string, substring)
D) startswith(substring)
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
22
The __________ operator can be used to determine whether one string is contained in another string.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
23
Which method would you use to determine whether a certain substring is the suffix of a string?
A) endswith(substring)
B) find(substring)
C) replace(string, substring)
D) startswith(substring)
A) endswith(substring)
B) find(substring)
C) replace(string, substring)
D) startswith(substring)
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
24
When the operand on the left side of the * symbol is a string and the operand on the right side is an integer,the * becomes the ___________ operator.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
25
What will be the value of the variable string after the following code executes?
String = 'abcd'
String.upper()
A) 'abcd'
B) 'ABCD'
C) 'Abcd'
D) Nothing; this code is invalid
String = 'abcd'
String.upper()
A) 'abcd'
B) 'ABCD'
C) 'Abcd'
D) Nothing; this code is invalid
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
26
Each character in a string has a(n)__________ which specifies its position in the string.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
27
What list will be referenced by the variable list_strip after the following code executes?
My_string = '03/07/2018'
List_strip = my_string.split('/')
A) ['3', '7', '2018']
B) ['03', '07', '2018']
C) ['3', '/', '7', '/', '2018']
D) ['03', '/', '07', '/', '2018']
My_string = '03/07/2018'
List_strip = my_string.split('/')
A) ['3', '7', '2018']
B) ['03', '07', '2018']
C) ['3', '/', '7', '/', '2018']
D) ['03', '/', '07', '/', '2018']
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
28
What will be the value of the variable string after the following code executes?
String = 'Hello'
String += ' world!'
A) 'Hello'
B) ' world!'
C) 'Hello world!'
D) Nothing; this code is invalid
String = 'Hello'
String += ' world!'
A) 'Hello'
B) ' world!'
C) 'Hello world!'
D) Nothing; this code is invalid
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
29
The third number in string slicing brackets represents the ___________ value.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
30
The __________ method returns True if the string contains only numeric digits.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
31
A(n)__________ is a span of characters that are taken from within a string.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
32
The __________ method returns the list of the words in a string.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
33
What will be assigned to the string variable pattern after the following code executes?
I = 3
Pattern = 'z' * (5 * i)
A) 'zzzzzzzzzzzzzzz'
B) 'zzzzz'
C) 'z * 15'
D) Nothing; this code is invalid
I = 3
Pattern = 'z' * (5 * i)
A) 'zzzzzzzzzzzzzzz'
B) 'zzzzz'
C) 'z * 15'
D) Nothing; this code is invalid
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
34
What will display after the following code executes?
Password = 'ILOVEPYTHON'
If password.isalpha():
Print('Invalid,must contain one number.')
Elif password.isdigit():
Print('Invalid,must have one non-numeric character.')
Elif password.isupper():
Print('Invalid,cannot be all uppercase characters.')
Else:
Print('Your password is secure!')
A) Invalid, must contain one number.
B) Invalid, must have one non-numeric character.
C) Invalid, must contain one number.
Invalid, cannot be all uppercase characters.
D) Your password is secure!
Password = 'ILOVEPYTHON'
If password.isalpha():
Print('Invalid,must contain one number.')
Elif password.isdigit():
Print('Invalid,must have one non-numeric character.')
Elif password.isupper():
Print('Invalid,cannot be all uppercase characters.')
Else:
Print('Your password is secure!')
A) Invalid, must contain one number.
B) Invalid, must have one non-numeric character.
C) Invalid, must contain one number.
Invalid, cannot be all uppercase characters.
D) Your password is secure!
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
35
A(n)__________ exception will occur if you try to use an index that is out of range for a particular string.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
36
The isalpha()method returns __________ if the string contains only alphabetic characters and is at least one character in length.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
37
The __________ method returns a copy of the string with all the alphabetic letters converted to lower case.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck