is a high-level language like C, C++, Perl and Java. It is considered an interpreted language because Python programs are executed by an interpreter.
Two ways to use the interpreter:
Interactive mode
Script mode
Interactivemode
you type Python programs and the interpreter prints the result. It is convenient for testing small pieces of code because you can type and execute them immediately.
Script mode
can be stored in a file and use the interpreter to execute the contents of the file. advisable for codes with more than few lines as you can save, modify and execute them in the future.
Program
sequence of instructions specifies how to perform a computation.
Programming is a process of breaking a large, complex task into smaller and smaller subtasks.
Input - Get data from the keyboard, a file, or some other device.
Output - Display data on the screen or send data to a file or other device.
Math - Perform basic mathematical operations like addition and multiplication.
conditional execution - Check for certain conditions and execute the appropriate sequence of statements.
Repetition - Perform some action repeatedly, usually with some variation.
Debugging is a process of tracking
programmingerrors.
Programming errors are called bugs.
Three Kinds of Errors in a Program:
Syntax Errors
Runtime Errors
Semantics Errors
Syntax refers to the structure of a program and the rules about that structure.
Syntax errors are produced by Python when it is translating the source code into byte code. They usually indicate that there is something wrong with the syntax of the program.
Example: Omitting the colon at the end of a def statement.
Runtime Errors are produced by the interpreter if something goes wrong while the program is running.
Example: An infinite recursion eventually causes the runtime error ”maximum recursion depth exceeded.”
Semantics Errors are problems with a program that runs without producing
errormessages but doesn’t do the right thing.
Example: An expression may not be evaluated in the order you expect, yielding an incorrect result.
value is one of the basic things a program works with, like a letter or a number.
Different types of values:
Numeric: integer, floating-point value
String
integer a type that represents whole numbers.
floating point value a type that represents numbers with fractional parts.
String a type that represents sequences of characters.
variable is a name that refers to a value.
A statement is a unit of code that the Python interpreter can execute.
An expression is a combination of values, variables, and operators.
Order of Operations:
Python follows PEMDAS:
Parentheses, Exponentiation, Multiplication and Division(same precedence), Addition and Subtraction(same precedence), (Operators with the same precedence are evaluated from left to right.)
concatenation - means joining the strings by linking them end-to-end.
Comments - has a symbol #, programs to explain in natural language what the program is doing.
5 STRATEGY OF USING MAXVAL FUNCTION:
COMPARE EACH TO ALL
DECISION TREE
SEQUENTIAL PROCESSING
Loop Processing
USE PYTHON MAX() FUNCTION
max of three - problem can be extended to more than three numbers.
EXCEPTION HANDLING
> done with a special control structure that is similar to a decision.
> This is being done using a try statement.
SYNTAX:
try:
<body>
except <ErrorType>:
<handler>
set - is a well-defined collection of objects called elements.
PYTHON’S BUILT-IN SET TYPE HAS THE FOLLOWING CHARACTERISTICS:
> Sets are unordered.
> Set elements are unique. Duplicate elements are not allowed.
> set itself may be modified, but the elements contained in the set must be of an immutable type.
set is initialize using set() or {},
Syntax: set(<iterable>) or {<obj>,...,<obj>}.
SET COMPREHENSION is a convenient way to generate a set.
Syntax: {<expression> for <variable> in <iterable> if <condition>}
In Python, we can identify if an element is in a set using Syntax: <expression> in <set>
FROZEN SET- which is in all respects exactly like a set, except that a frozenset is
Immutable.
frozen set- can perform non-modifyingoperations on a frozenset. it is useful to representssets that contain sets.