4

What is the difference between code cell and input cell?


enter image description here

Kuba
  • 136,707
  • 13
  • 279
  • 740
vasili111
  • 1,215
  • 8
  • 13

1 Answers1

8

TLDR:

  • Code is the default one in .wl .m files, content of Input in those cases will be commented so it won't run with << my.wl ( more: 9921
  • Input does a little formatting, auto indents, line wrap etc., in Code it is what you type.
  • Code is an InitializationCell so it will or ask you about evaluating it before you run anything in a fesh notebook. Could be nice or annoying, depending on your workflow.

Personal note, I prefer to control my formatting, don't care about 2D input and am annoyed by 'evaluate initialization cells prompt' so I work with .wl files with Code cells on daily basis.

Differences:

styles = {CurrentValue[{StyleDefinitions, "Code"}], CurrentValue[{StyleDefinitions, "Input"}]};

{ Complement @@ styles, Complement @@ Reverse@styles } // KeyUnion // Normal // Transpose // Map[ { #[[1, 1]] , #[[1, 2]] /. m_Missing :> CurrentValue[{StyleDefinitions, "Code", m[[2]]}] , #[[2, 2]] /. m_Missing :> CurrentValue[{StyleDefinitions, "Input", m[[2]]}] } & ] // Sort // Prepend[{"", "Code", "Input"}] // Grid[#, Alignment -> Left, Background -> {{}, {{GrayLevel@.9, None}}}, Dividers -> {{2 -> True}, {2 -> True}}] &

enter image description here

Kuba
  • 136,707
  • 13
  • 279
  • 740