Computer Science, asked by rinisen, 6 months ago

What will be the output on executing the following set of commands in the shell? >>>str= "Hello" >>>str[:2]

Answers

Answered by gaganadithyareddy9
13

Answer:

This is in python...

'str' variable stores "Hello" in it and in the second line you are performing slicing operation on a string...

The output will be:

He

Because ':' represents that the slicing must start from beginning of string and 2 represents that it should stop at 2nd position..

Answered by SaurabhJacob
1

The output will be "He".

The given lines are in Python Programming Language.

The first statement is storing a string "Hello" in the variable str.

                               >>> str = "Hello"

In the second statement, the String Slicing operation is taking place.

                               >>> str[:2]

String Slicing syntax is,

                               >>> variable_name[start : stop]

As in the second statement starting is not given so the interpreter will start from the beginning and will stop at 2.

                                    H        e        l        l        o

                                    0         1        2        3        4

Hence the output will be "He".

Similar questions