Search code examples
pythongoogle-colaboratory

cant run multiple codes in a single code cell


I started with colab today and still learning. However I faced problem. When running several commands in code cell, it will run only the last command, for example:

str1='hello world'

str[0:4]

str[2:5]

When all of the above in one code cell and you press run. Only the output of str[2:5] will be shown,

If print statement is added to both of slices, it will work.

Is this intended, or am I doing something wrong?


Solution

  • As written here

    Getting started: The document you are reading is not a static web page, but an interactive environment called a Colab notebook that lets you write and execute code.

    For example, here is a code cell with a short Python script that computes a value, stores it in a variable, and prints the result:

    So - Yes, this works as intended. Colab will show the output of the last command in the cell

    You can create multiple cells if you want to show more output. Or, as you allready found, use print to show strings.