Unit 1
Unit 1
Interpreter
- translates program code line by line
Compiler
- translates the entire program completely
Interpreter and Compiler
Compiler
Interpreter
"python file_name.py"
What is a Program
- a sequence of instructions that specifies
how to perform a task
+ (addition)
- (subtraction)
* (multiplication)
/ (division)
** (exponentiation)
Values and Types
value - one of the basic units of data
type - a category of values
Basic Types
int - integers (don't use commas!)
float - floating-point numbers
str - string
Examples
use the type() function to identify the type of the value
name that
assignment refers to a
operator value
variable_name = value
Good examples:
How to name your variables
make them meaningful
vs
vs
Expressions vs Statements
Expression
a combination of values,
variables, and operators
the interpreter evaluates it
--> finds the value
Expressions vs Statements
Statement
a unit of code that has
an effect
a unit of code that the
Python interpreter can
execute --> does not
produce values
Script Mode
- this is interactive mode
Illegal Operation:
String Operations
String Concatenation: String Repetition:
Comments
- used to document your code
- helps other programmers understand your code
- use # to create a single-line comment
- use 3 single quotes (’’’) to create a block comment
Debugging
- process of tracking down programming errors (bugs)
Programmers 80%
of the time
Kinds of Errors
Syntax Error
- syntax is the set of rules that define how
we make valid statements in a language
- syntax errors occur when there is
something wrong with the syntax
indention is required here