At first glance, Python looks a lot like BASIC. It has similar operators, (functions that act like miniature programs) like print, or input, and appears to have a familiar syntax when viewed from a distance. And this makes sense; Python was created in the early 90's, when BASIC still reigned supreme among beginner programming languages. But Python is way more different than BASIC. For example, here's the common "Hello World" program written in Ti-BASIC, Applesoft BASIC, and Python:
Ti-BASIC: Applesoft BASIC: Python:
:Disp "Hello World" 10 PRINT "HELLO WORLD" print("Hello World")
Notice the difference between Ti-BASIC, Applesoft BASIC, and Python. Applesoft and Ti-BASIC are essentially the same except for a few slight differences (mostly the Ti-84's use of the equivalent to the print command, "Disp", and Applesoft's program line numbering system (the "10")). Python also appears to be the same, but don't let looks deceive you; it isn't. First of all, Python's operators need to be in lowercase in order to work, unlike the BASIC variants. Ti-BASIC's operators are their own characters, so you do not even need to spell them out, and operators entered into Applesoft will automatically be converted to uppercase. Python also needs it's arguments (the values needed for the operators to function) in some statements to be surrounded by parenthesis's, while Basic only needs quotations.
It might seem that Python is a bit more complicated and obtuse compared to BASIC, but Python is a powerful modern programming language. Just look at the degree of modification that Python's print function allows. By inserting special escape sequences (special characters that can perform different tasks) you can easily make big changes in how a print statement is executed. For example, placing /n in a statement creates a new line prior to the following string of text. BASIC would require a blank print statement to do the exact same thing.
For a more comprehensive comparison, here's the "Silly Strings" program from my programming book written in Python (Ignore the excessive use of the + operator. This program was originally made to demonstrate that operator and the ability to repeat a statement):
Python:
#Silly Strings
#Demonstrates string concatenation and repetition
print("You can concatenate two" + " strings with the '+' operator.")
#Concatenation Demonstration
print("\nThis string " + "may not " + "seem terr" + "ibly impressive."\
+ " But what"+ "you don't know" + " is that\n" + "it's one real" \
+ "l" + "y" + " long string, created from the concatenation " \
+"of " + "twenty-two\n" + "different strings, broken across " \
+ "six lines." + " Now are you" + " impressed? " + " " + "Okay,\n" \
+ "this " + "one " + "long" + " string is now over!")
#RIP Fingers. This keyboard sucks.
#Statement Repeat Demonstration
print("\nIf you really like a string, you can repeat it. For example,")
print("who doesn't like pie? That's right, nobody. But if really")
print("like it, you should say it like you mean it:")
print("Pie" *10)
input("Press enter to exit")
Running in the Windows Command Line:
And now the equivalent program in Applesoft Basic:
20 PRINT " "
30 PRINT "This string may not seem terribly impressive, but what you don't know is that it's one really long string, created from the concatenation of twenty-two different strings, broken across six lines.
40 PRINT "Now are you impressed? Okay, this one long string is over!"
50 PRINT "If you really like a string, you can repeat it. For example, who doesn't like pie? That's right, nobody. But if you really like it, you should say it like you mean it:"
60 For I=1 to 10
70 Print "Pie"
80 Next I
Running in a apple // emulator in 80 column mode:
Running in a apple // emulator in 80 column mode:
It may seem that the python version is a lot longer and cryptic than BASIC, but it is anything but that. Notice the / escape sequence in the concatenation demonstration. Python allows you to continue an entire string (a series of text) of a single statement on multiple lines. Applesoft doesn't have the ability to do that, so you have to either make multiple print statements or put it all into one single long print statement, and hope that don't reach the max character limit imposed by software bugs. It also cannot create new lines mid-argument, which would again need another print function. Python also allows programmers to repeat a statement multiple times on the fly by adding "*10". Meanwhile, BASIC needs 3 more lines of code for a For Next function in order to create a loop that repeats the word "Pie" 10 times. Even the Bell Character (a character that induces the computer to beep) is simpler in python. In Applesoft, you need to address a specific memory register in the computer to create the bell character in code, but Python only needs /a. Good luck trying to do this type of stuff on a Ti-84.
All in all, I'm impressed by Python. It seems to be even more powerful than and as intuitive as BASIC. The modability of it is unique and expansive, and given that it is a modern programming language, it can be used anywhere. I think I'm going to really like Python!
*Updated: Added emulator photos, fixed grammatical errors, and made some adjustments.
Apple //jse Emulator by Will Scullen
Bibliography:
Python Programming for the absolute beginner, Third Edition by Michael Dawson
Applesoft Basic Programming Reference Manual (1978) published by Apple Computer Inc.