Chapter 1 - Introduction

Technology is constantly changing and improving. Technology has the power to affect all aspects of our society: family life, education, communication, entertainment, public health, and more. For those who understand the fundamentals of technology, technology is a tool that they have power over. Those who do not understand these fundamentals may find themselves as slaves to the technology they use. Learning to code is an important part of learning the fundamentals of the technologies that are such an integral part of modern society.

What is Coding?

Simply put, coding is writing commands to a computer. Computer code is a series of specific, unambiguous commands that tell the computer what to do. Computers function by writing data to memory, reading data from memory, and performing calculations on that data. Commands can be used to tell the computer to display text, to perform mathematical functions on numbers, to process user input, etc.

What is a Programming Language?

Unfortunately, computers don't speak English. English is too ambiguous for computers to understand perfectly. Here are some common examples of English ambiguity:

  • A good life depends on the liver - "Liver" may be an organ or a living person
  • Foreigners are hunting dogs - Are the foreigners going hunting for dogs, or are they dogs that hunt?
  • Each of us saw her duck - Did we see a duck that she owns, or did we see her perform the action of ducking down?
  • Passerby helps dog bite victim - Did the passerby help a victim of a dog bite, or did the passerby help a dog to bite a victim?

To avoid these problems with ambiguity, computers speak a language called binary or machine code. Binary is a language made up of 0s and 1s, and the computer hardware interprets these 0s and 1s (known as bits) to control electrical voltages in the computer, and those electrical voltages carry out the commands. For example, on a 64-bit operating system, every command is composed of a series of 64 bits. In the early days of computing, programmers wrote commands in 0s and 1s. This works well because computers can understand the language of binary without ambiguity.

Unfortunately, it is very hard for humans to read and understand binary code. Writing and maintaining binary code is difficult and requires a lot of work just to write basic commands that accomplish very little. What we need is a language that computers can understand perfectly and that humans can easily read and write. Programming languages meet the needs of both computers and human programmers. Programming languages define language rules that are unambiguous and can be translated directly into binary for computers, and they also use syntax that is relatively easy for humans to read and write.

Programming languages are often described as either being "high-level" or "low-level" languages. A high-level language is a programming language that is easier for humans to read and write, but requires more work to be translated (or compiled) into binary and thus gives the programmer less direct control over the computer. By contrast, a low-level language is one that is harder for humans to read and write, but translates more directly into binary and thus gives the programmer more direct control over the computer. High level languages—such as Java, C#, C++, Python, PHP, and JavaScript—are ideal for learning basic coding skills and for architecting big applications. Low level languages—such as Assembly and C—are ideal for learning the underlying fundamentals of computing and for writing powerful core software such as operating systems.

What is Python?

Python is a high-level programming language that can run on all common operating systems and prides itself on being easy to learn. This textbook allows you to write and run Python code in your internet browser, but some activities will require you to write Python files on your own computer and submit them for evaluation. You can learn more about how to install and run Python on your own computer at The Install Python chapter will also help walk you through the process of installing and running Python on your own computer.

One of the goals of the Python programming language is to define intuitive syntax that makes it more human-readable. For example, to print text to the screen, the command is simply print. Commands like this are known as functions. Functions take some kind of input and produce output. The print function takes a string of text wrapped in quotation marks as input, then prints that text to the screen.

Use the space below to play with the print function to print text to the output window. Click "Run" to see how the example works.

# Print strings of text to the screen print("Hello, world!") print("Python is fun and easy to learn!") # Print strings of text to the screen print("Hello, world!") print("Python is fun and easy to learn!") test_function("print")
Use the print function to print text to the screen. Use the format print("Enter text here").

Comments in Code

In the example above, you'll notice the green text that says # Print strings of text to the screen. That line is a comment. Comments are not seen by the computer. They are not commands, and they are not translated into binary for the computer to run. Comments are just for programmers to see; they are notes that a programmer writes about the code. Comments are often used to briefly describe what the code is doing so that when you come back to look at your code later, you can easily find the code you need to and have a basic understanding of what it's supposed to be doing.

In Python, single-line quotes start with #. That tells the computer that everything following # on this line is a comment and the computer should ignore it. For comments that take up multiple lines, use """ at both the beginning and the end of the comment.

# Print a greeting print("Hello, world!") """ Print something funny, perhaps something from a classic book or one of your favorite movies """ print("Everything is funny, as long as it's happening to somebody else")