Python Notes
Python Notes
Python
Python:
Python is an object oriented very high level programming language.
1- ABC language.
2- Modula-3
Disadvantage of PYTHON:
1- Not the faster language.
2- Lesser libraries.
3- Not strong and typing binding.
4- Not easily convertible.
5- Interpreter.
6- Compiler.
Working in PYTHON:
→In interactive mode: Here we execute the code one by one and get the result one by one. Here we
can’t save the file. This is also known as PYTHON SHELL.
→In script mode: Here we write the full program ,then save it after that we get the result.
Chapter-2-Python Fundamental
Tokens:
The smallest individual unit in a program is known as TOKENs.
Types of TOKEN:
1- Keywords. (RESERVED WORDS)
2- Identifiers(NAME).
3- Literals.
4- Operators.
5- Puncuators.
Literals/Values:
Literals are the data items that have a fixed value.
Types of LITERALS:
1- String literals
2- Numeric literals
There are 4 types of NUMERIC LITERALS:
1- Plain integer
2- Long integer
3- Floating point numbers
4- Imaginary numbers
3- Boolean literals.
4- Special literals.
5- Literals collection.
Operators:
Operators are used to perform some mathematical operations on variables and on other
objects(operand) in an expression.
Types of OPERATORS:
1- Unary operators→ One operand require to operate.
FOR EXAMPLE→ unary plus, unary minus, E.T.C.
2- Binary operators→ Two operand require to operate.
FOR EXAMPLE→ Arithmetic operator, Bitwise operator, Shift operator, E.T.C.
CHAPTER-3-Data Handling
Data:
Any type of information which can be processed in computer is known as data. (text, number, Image,
audio, video).
Data type:
Identifies type of value and Provides sets of valid operations.
3- Sets:
4- None:
5- Mappings:
1- Dictionaries.
Operators:
The operator is a symbol that perform a specific operation on two operands
Types of operators:
1- Arithmetic operator→ +, -, *, /, %(reminder), **(Exponent), //(Floor division).
2- Comparison operator→ ==,!=,<=, >=, <,>.
3- Assignment operator→ =, +=, -=, *=, %=, **=, //=.
4- Logical operator→ and, or, not.
5- Bitwise operator→ &(binary and), /(binary or),^( binary XOR), ~(negation),<<(left shift),
>>(right shift).
6- Membership operator→ in, not in. 7-Identity operator→
CHAPTER-4-Flow Of Control
Statement flow of control:
In a program statement may be sequentially selectively or iteratively. Every programming language
provides constructs to support sequence, selection or iteration.
A conditional is a statement set which is executed, on the basis of result of a condition. A loop is
a statement set which is executed repeatedly, until the end condition is satisfied.
Compound statement:
A compound statement represents a group of statements executed as a unit. The compound
statement of python are written in a specific pattern.
<indented body>
The conditional and the loops are compound. The contained statements are not written in the same
column as the control statement rather they are called a block.
The first line of compound statement it’s header contains a colon(:) at the end of it.
Simple statement:
Compound statement are made up of simple statement. Any single statement is a simple statement
in python.
Empty statement:
The simplest statement is the empty statement which does nothing. In python an empty statement is
the ‘Pass’ statement.
plan if conditional
Storing condition:
Sometimes the condition being used in code are complex and repetitive. In such cases to make your
program more readable, you can use named conditions you can store conditions, in a name and then
named conditional in the if statements.
Statement Looping:
Python provides two kinds of loops:
1- For loop
2- While loop
Jump statements:
Break and continue
Python offers two jump statements-break and continue-to be used within loops to jump out of loop-
iterations.
The end clause of a python loop executes when the loop terminates normally. Not when the break
statement terminates the loop.
Nested loop:
A loop may contain another loop in its body. This form of a loop is called nested loop. But in a nested
loop, the inner loop must terminate before the outer loop.
CHAPTER-5-String Manipulation
String:
Strings in python are stored as individual characters in contiguous location, with two way index for
each location. Strings are immutable and hence item of assignment is not supported.
Name=”hello”
Traversing a string:
Traversing refers to iterating through the elements of a string, one character at a time.
Code=”abc”
for ch in code:
print (ch,’~’end=’’)
String operator:
String supports only two operator;
+(concatenate)
*(replication)
print(“hello”*3)
Membership operator:
These are two membership operator for string;
‘in’
‘not in’
Comparison operator:
Python’s standard comparison operator all relational operator apply to string also.
The opposite of ord() is chr() which take the integer value and return the character
corresponding to that ASCII value.
String slice:
Slice refers to a part of the string, where string are sliced using a range of indics.
st=’Hello world !’
st=[1:3]
Result(el)