1. What is printed by the following code? user_str = ‘aabbcc’ print(user_str[2:]
ID: 3870254 • Letter: 1
Question
1. What is printed by the following code? user_str = ‘aabbcc’ print(user_str[2:]) print(user_str[1:4]) print(user_str[1: :2]) print(user_str[:-2]) index_int = 0 print(user_str[index_int],user_str[index_int+2])
2. What is printed by the following code? print(“The interest rate is {:.2f} for you.”.format(2.7)) print(“{:>15s}: {:<8.1f}”.format(“Length”,23.875))
3. Will the following code work in Python without producing an error? Why? alpha = “Hello.” alpha[5] = ‘!’
4. What is the value of the following string methods and expressions? T = ‘TEXAS TECH UNIVERSITY’ S = ‘Computer Science Department’ T.title() T.find(‘H’,5,10) S.count(‘e’,7,-4) len(S) S[-2] ord(T[4]) S[:8]+T[6:10]
Explanation / Answer
user_str='aabbcc'
print(user_str[2:])
print(user_str[1:4])
print(user_str[1: :2])
print(user_str[:-2])
index_int = 0
print(user_str[index_int],user_str[index_int+2])
'''
output
======
bbcc
abb
abc
aabb
a b
'''
print("The interest rate is {:.2f} for you.".format(2.7))
print("{:>15s}: {:<8.1f}".format("Length",23.875))
'''
output
=======
The interest rate is 2.70 for you.
Length: 23.9
'''
S='Computer Science Department'
T.title()
T.find('H',5,10)
S.count('e',7,-4)
print (len(S))
print (S[-2])
print (ord(T[4]) )
print(S[:8]+T[6:10])
'''
output
======
27
n
83
ComputerTECH
'''
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.