From the course: Introduction to Career Skills in Software Development

Basic statements and expressions - Python Tutorial

From the course: Introduction to Career Skills in Software Development

Basic statements and expressions

- Statements are the building blocks of any program. They are the individual actions that you want your program to take. Each statement can be made up of keywords, expressions, and operators. Let's look at them one at a time, starting with operators. Operators are symbols that tell the computer to perform an action with some input. In this table, you can see a partial listing of some operators that should be familiar to you. For example, the plus symbol is used for addition, minus for subtraction, an asterisk or star to represent multiplication, and a forward slash for division. These are known as arithmetic operators, as they take numerical values for their input and perform an arithmetic operation. For example, if we take the following, 10 + 2, what does that equal? 12, correct. (laughs) Let's try another one. 10 / 2 + 3. What does this evaluate to? Yes, it's 8. The result of these operations that break down to a single value are called expressions. You'll encounter various types of expressions in programming. The result may be a number, as we've seen a few examples of here. Or it could be other values, like true or false or something else entirely. The final component of a statement that I want you to be familiar with is a keyword. A keyword is a reserved word that means something special to the given programming language. Let's take a look at a keyword in the Ruby programming language. The keyword is unless. This means we can't create our own variable with the same name. The program would not compile, as the keywords need to be used according to the rules of the language. Bear in mind, each programming language has a set of reserved keywords useful for building robust statements. Computer programs are made up of statements, statements that can perform a mathematical calculation, print something to the screen, or even make a choice between two code paths. This powerful concept is the foundation of all code that programmers write.

Contents