In the interactive shell, type, and hit enter:
print(“This is the interactive shell.”)
- print (case-sensitive, all lowercase) is a function. It’s a program itself found in most programming languages.
- The text in the quotes is called a string. A type of data.
- You wrote your first program, and were presented with immediate feedback.
- Open up the IDLE editor File > New Window, and enter the same text.
- Save and run it (Press F5). So the editor allows you to create programs that you can save.
Comments are text prefixed with a #, and are ignored in programs. Great way to annotate code, so you and others can understand it.
print(“Hello, World!”) # Prints text to the screen
input(“\nPress a key to exit”)
input is another function for dealing with user input. \n is an “escape sequence” that operates on a “new line”. There’s also “\t”, for “tab”. Try it.
Challenges:
- Print some text, like “Hello, World!”, your name, etc, in both the shell and as programs via the editor.
- Insert comments into your print programs (above the print line, below it, on the same line…)
- Write a program that prints something on the first line, and on the second with a indented tab, and requires you to press enter before it ends.