Python Forum

Full Version: What will the following code output?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
What output will the following code give?
>>> word=’abcdefghij’
>>> word[:3]+word[3:]
What do you think? Did you try to run it if not able to say just from looking at it?
It would have been faster and more efficient to type the same code in the python interpreter instead of the forum!
The output is:

Output:
'this sounds like homework'
If you are on linux, just enter on your keyboard :
python3
If you are on windows, download the last release on :
https://www.python.org/downloads/windows/
If you cannot install because you don' have administrative access... try to find some web site with a python terminal for free.
You can also buy a raspberrypi (arround 10$), but you will need also a screen and a keyboard (take them from the pc you used for the forum), and you will have to download and install raspbian.
If you fail with all of that, read the doc : https://docs.python.org/3/tutorial/index.html , your brain will give you the answer quickly.
The output is ‘abcdefghij’. The first slice gives us ‘abc’, the next gives us ‘defghij’.