Free Python course. Sign Up for tracking progress →
Python: Methods as expressions
Methods are expressions, like variables or function calls, which means they can be combined in different ways.
For example, you can use them in operations:
name = 'Shaya'
'hi, ' + name.upper() + '!' # hi, SHAYA!
Or in function parameters:
name = 'robb'
print(name.lower()) # => robb
num1 = 5
num2 = 30
# bit_length() - calculates the number of bits needed to represent a number in binary form
print(num1.bit_length() + num2.bit_length()) # => 8
Instructions
Find the characters N and , (comma) inside the text in the text
variable. Print their indices on the screen. Expected output from the tests:
Index Of N: 0 Index Of ,: 25
Your task is to find these indices in the string using the .find()
method and put them in print()
without using intermediate variables. If you want to split the output into two lines, you may need \n
.