Programming is Magic! It really is. There's a quote from Arthur C. Clarke: > Any sufficiently advanced technology is indistinguishable from magic. And when you think about magic and casting spells - each magic system has rules about who and what can cast the spells. Sometimes the spell casting goes wrong. Other times a spell is vastly complicated and requires weeks of preparation and setup, with esoteric ingredients. Our aim is to teach you how to become a wizard, capable of casting your own spells to perform the magic that you desire. Open up your Python interpreter and type in the following incantation: >>> print("Programming is magic!") Programming is magic! You have just cast your first spell! How does it feel? This was a very basic spell, but the amount of power you're wielding here is impressive. In programming terms - you have written your first program, commonly known as "Hello, world!" because usually the spell is cast the following way: >>> print("Hello, world!") Hello, world! You now have cast two different spells. You are a wizard now! A beginner, sure, but still a wizard! This print spell (or function) is a very basic kind of spell that allows you to send text to the screen. Computers are a type of electric machine that have at their core, input and output. When you type `print("Programming is magic!")`, you are providing _input_. Then the computer processes your input and provides the output, which you see on the next line. The other ingredient here is the quotation marks. When you're casting spells in Python, you can use either single or double quotation marks to make a _string_. A string is just the way that computers understand text. And when you're casting the print spell you can provide multiple strings, which will be printed together. >>> print("Programming", "is", "magic!") Programming is magic! If you typed this in exactly, you should see the same output. In programming, our magic is *very* precise. If you are off one way or another, your spell can go haywire. Either you'll have a logic error, or some kind of exception. A logic error would be something like >>> print("Programming ", " is ", " magic!") Programming is magic! If you didn't intend to have three spaces between your words, anyway. An exception is a kind of error where the magic stops. This is nothing to be afraid of! And the most powerful wizard will create exceptions _all the time_. Sometimes even on purpose! Here is one spell that will create an error: >>> print("Exceptions are not scary!') File "", line 1 print("Exceptions are not scary!') ^ SyntaxError: EOL while scanning string literal It's unlikely that this caused your hair to turn purple or fall out. If it did, please let me know because I have never seen that happen to a wizard casting these kinds of spells, and would be quite an exciting development! I wanted to introduce you to exceptions early, so that you can be comfortable with them. Casting spells in Python provides you very useful information on what went wrong with your spell casting. And Python error messages are most usefully read from the bottom up. In this case: "SyntaxError" tells you what kind of exception it is. As our magic has evolved, we've learned how to even further improve our understanding of what and when things went wrong. Here, the caret (`^`) symbol shows us exactly where in our spell we made the wrong move. Python encountered an EOL, or End Of Line, character when it was looking to close our string. Because we used a double quote and a single quote when we waved our magic wand (typed it on our keyboard), we weren't really closing the string. On the line above we'll see the line of code - because we're casting our spells in the protection circle of the interactive interpreter, and it's a very basic spell, it's easy to know what went wrong. But in the future as we build far more complex spells, with different scrolls (or files), and rely on other spellbooks (or libraries), the error reporting becomes super powerful. And up yet another line it says `File "", line 1` -- computers have something called "standard in" and "standard out", stdin and stdout for short. These are the two most basic ways that we send magic in and get effects out from a computer. `stdin` means something called the command line, which is the basic interface for magic. `stdout` is how things come out of the command line -- and there *is* another interface `stderr` (if you guessed "standard error", you're right!) where errors are (usually) printed. If you'd like the arcane knowledge behind this, wizards in days of yore would type into a physical keyboard that was more akin to a typewriter, and the output would literally be typed onto a piece of paper. Magic was wild and untamed in those days. Errors are usually nothing to be afraid of. Very often the worst thing they'll do is cause your spell to fizzle out, or your program to stop running. If you're working with more advanced spells, it's possible that you can have a more serious impact, causing things like data loss. Or, if you have advanced far enough as a wizard where you begin interfacing with the real world, you can accidentally destroy rockets. But that's a long way off -- a simple error message is of little consequence. With the knoweledge that you have so far, can you fix the error on your own? There are two different options you can take: >>> print("Exceptions are not scary!") >>> print('Exceptions are not scary!') Either incantation works. One of the advantages of being able to use different quotes means you can use the other quote within your string: >>> print("What's up?") >>> print('I told him, "Alakazam!"') One final note on the basic strings, there's another spell you can cast, called a triple-quoted string, using either double or single quotes: >>> print('''This kind of string ... can span multiple ... lines and can contain the other quotes "'" ... as long as there aren't three of them together ... though you can use three of the other kind """ ... like that.''') This kind of string can span multiple lines and can contain the other quotes "'" as long as there aren't three of them together though you can use three of the other kind """ like that. >>> print("""You can also use them on a single ''' line, if you want.""") You can also use them on a single ''' line, if you want. Now you know how to cast the most basic of all spells. It may not be particularly impressive, but you *are* programming, and since Programming is Magic, you are casting spells and you *are* a wizard! In our next lesson we will learn how to use different ingredients, or data types, in our spells, along with how to cast spells that allow people to interact with our magic (or, accept input).