That's an excellent question! The Python interpreter can run virtually any valid Python code. While you're in the >>> prompt, you're directly interacting with the Python execution environment.
Here are some categories of "commands" or operations you can perform:
-
Mathematical Operations: As you've just seen, it acts like a powerful calculator.
10 / 3 # Output: 3.3333333333333335 5 * 5 # Output: 25 2 ** 3 # Exponentiation (2 to the power of 3) # Output: 8 -
Working with Variables: You can assign values to variables and then use them.
x = 10 y = 5 x + y # Output: 15 message = "Hello, Labby!" print(message) # Output: Hello, Labby! -
Strings: Manipulating text.
"Hello" + " World" # Output: 'Hello World' "Python " * 3 # Output: 'Python Python Python ' "LabEx".upper() # Output: 'LABEX' -
Lists, Tuples, Dictionaries (Data Structures): You can create and modify these fundamental data types.
my_list = [1, 2, 3] my_list.append(4) print(my_list) # Output: [1, 2, 3, 4] my_dict = {"name": "Labby", "age": 1} print(my_dict["name"]) # Output: Labby -
Functions: You can define and call your own functions.
def greet(name): return "Hello, " + name + "!" greet("Alice") # Output: 'Hello, Alice!' -
Control Flow (though less common for simple interactive use): You can even write
ifstatements orforloops, though for multi-line code, it's usually better to write a script.if 5 > 2: print("Five is greater than two") # (Press Enter twice after the indented line) # Output: Five is greater than two -
Importing Modules: Extend Python's functionality.
import math math.sqrt(25) # Output: 5.0
Special Interpreter Commands:
help(): Brings up the Python help utility. You can typehelp(print)for example, to get documentation on theprintfunction. Typequitto exit help._: This special variable holds the result of the last evaluated expression.5 * 6 # Output: 30 _ + 10 # Output: 40exit()orquit(): These functions will exit the Python interpreter and return you to the shell prompt ($).
The interactive interpreter is an amazing tool for quickly testing ideas, understanding how language features work, and debugging small snippets of code.
As you progress in your Python journey, you'll discover more and more that the interpreter can do! For now, keep experimenting with the calculations mentioned in the step.