WORK WITH STRINGS
Which of the following statements correctly describes strings? Select all that apply.
Strings must be placed in quotation marks. Strings are also immutable. This means they cannot be changed after they are created and assigned a value.
What does the following code return? device_id = "uu0ktt0vwugjyf2" print(device_id[2:5])
This code returns "0kt". It uses bracket notation to take a slice of the value contained in the device_id variable. Indices start at 0 in Python. It extracts the characters at indices 2, 3, and 4. The character at index 5 is excluded from the slice.
What does the following code display? device_id = "Tj1C58Dakx" print(device_id.lower())
This code displays "tj1c58dakx". The .lower() method converts all uppercase characters into lowercase characters.
You want to find the index where the substring "192.168.243.140" starts within the string contained in the variable ip_addresses. Complete the Python code to find and display the starting index. (If you want to undo your changes to the code, you can click the Reset button.) (S1Q4-1) (S1Q4-2) What index does the substring "192.168.243.140" start at?
The substring "192.168.243.140" starts at index 32. You can determine this using the code ip_addresses.index("192.168.243.140"). Note that Python indices start at 0.
What does the code print("HELLO"[2:4]) output?
The code print("HELLO"[2:4]) outputs "LL". The first index in the slice is included in the output, but the second index in the slice is not included. This means the slice starts at the character at index 2 and ends one character before index 4.
Ready to test your recall?
Which of the following statements correctly describes strings? Select all that apply.
How confident are you in this answer?