What will be the output of the following python print statements for the string? str = 'SUNDEW' i) print(str*2) ii) print(str[4:]).
Answers
Answered by
1
Answer:
What will be the output of the following python print statements for the string? str = 'SUNDEW' i) print(str*2) ii) print(str[4:]).
ueh54
Answered by
2
★
i) SUNDEWSUNDEW
ii) EW
★
- The first statement outputs the string twice. It is because when we use multiplication operator after a string, it gets printed the number of times it is multiplied with.
- The statement str[4:] returns all the characters from fourth index[fifth character] to the last character.
★
- In Python, a list is a collection of items or elements, which can be of any data type (e.g. integers, strings, or other lists).
- Lists are mutable, meaning you can add, remove, or modify elements in a list after it has been created.
- You can create a list by enclosing comma-separated elements in square brackets.
- You can access elements in a list using their index, which starts at 0 for the first element.
- You can modify elements in a list by assigning a new value to the element at a specific index.
Similar questions