Python Programming: (LESSON 1) 9 Slides
Syntax
Displaying the output of a computer program:
print(1 + 2)
print(5 * 10)•
Ignoring certain lines of code by using code comments:
# print(1 + 2)
print(5 * 10)
# This program will only print 50
•Performing arithmetical operations:1 + 24 - 530 * 120 / 34 ** 3(4 * 18) ** 2 / 10
•When we give a computer a set of instructions, we say that we're programming it. To programa
computer, we need to write the instructions in a special language, which we call a programming
language.
•Python has syntax rules,
and each line of instruction has to comply with these rules. For example, print (23 + 7) print(10 -
6) print(12 + 38) doesn't comply with Python's syntax rules, and it causes a syntax error
.•We call the instructions we send to the computer code. We call each line of instruction a line of
code.
•When we write code, we program the computer to do something. For this reason, we also call
the code we write a computer program (or a program).
•The code we write serves as input to the computer. We call the result of executing the code
output.
•We call the sequence of characters that follows the # symbol a code comment.
We can usecode comments to prevent the computer from executing a line of code or to add
information about the code we write.
Programming Python Variables: Takeaways by Dataquest Labs, Inc. - All rights reserved © 2022
Syntax ConceptsTakeaways by Dataquest Labs, Inc. - All rights reserved © 2022Storing
values to variables:twenty = 20result = 43 + 2**5currency = 'USD'•Updating the value stored in
a variable:x = 30x += 10 # this is the same as x = x + 10•Syntax shortcuts:x += 2 # Additionx -=
2 # Subtractionx *= 2 # Multiplicationx /= 2 # Divisionx **= 2 # Exponentiation•We can store
values in the computer memory. We call each storage location in the computer'smemory a
variable.•There are two syntax rules we need to follow when we're naming variables:•We must
use only letters, numbers, or underscores (we can't use apostrophes, hyphens,spaces,
etc.).•Variable names can't begin with a number. •Whenever the syntax is correct, but the
computer still returns an error, we call this a runtimeerror.•In Python, the = operator tells us that
the value on the right is assigned to the variable on theleft. It doesn't tell us anything about
equality. We call = an assignment operator, and weread code like x = 5 as "five is assigned to x"
or "x is assigned five," not "x equals five." •In computer programming, we classify values into
different types — or data types. A value'stype offers the computer the information necessary to
process that value. Depending on thetype, the computer will know how to store a value in
memory, or which operations it can performon a value.•
Download as PDF
Page 1 of 1
7. Takeaways