Write the output of the following code :L=list(https://logikworks.in/)print(L[20 : -1])
Question
Write the output of the following code :
L=list(https://logikworks.in/)
print(L[20 : -1])
Solution
The code you've provided seems to be in Python, but it's incorrect. Python can't convert a URL directly into a list. If you want to convert a string into a list in Python, you need to put the string in quotes.
Here's the corrected code:
L = list('https://logikworks.in/')
print(L[20 : -1])
This code will output:
['.', 'i', 'n']
Here's the step by step explanation:
-
The
list()
function is used to convert the string 'https://logikworks.in/' into a list where each character (including punctuation and slashes) is a separate element. -
The
print()
function is used to print a slice of the list from the 20th index to the second last index. In Python, list indices start at 0, and negative indices count from the end of the list. SoL[20 : -1]
will output the elements from the 20th index up to (but not including) the last element. -
The elements at indices 20, 21, and 22 of the list are '.', 'i', and 'n', respectively. So, the output of the code will be ['.', 'i', 'n'].
Similar Questions
What is the output of the following code.l = [‘Logik', ‘works'] for i in l: i.swapcase() print(l)
What will the output of the following line of code be?print(list(range(10, 1, -1)))
What will be the output of the following Python code? t=(10,20,40,30) print(t[1:-1])
What will the output of the following program be?L1 = ['Vikas', 'Akshay', 'Sanskar', 'Mahima']print(L1[1][-1])
What will be the output of the following code snippet?for index in range(20, 10, -3) :print(index, end = ' ')
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.