CHAPTER-1-Getting Started With
Python
Python:
Python is an object oriented very high level programming language.
Developed by: GUIDO VAN ROSSUM in 1991.
Influenced with: Two programing language
1- ABC language.
2- Modula-3
Advance feature of PYTHON:
1- Easy to use.
2- Expressive language.
3- Interpreter language.
4- Its completeness.
5- Cross platform language.
6- Free and open source.
7- Variety of usage/application.
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.
There are 3 types of INTEGER LITERALS:
1- Decimal integer literals→1205, +85, -254.
2- Octal integer literal→0o123, 0o156.
3- Hexadecimal integer literals→0x123, 0x146,0X123.
FLOATING POINT literals or REAL literals:
1- Fractional form→12.53, -23.67.
2- Exponent form→ It consists of 2parts↓ for instance 5.8 can we written as 0.58*10-1=0.58E01
Mantissa=0.58 , Exponent=01
3- Boolean literal→ True False
4- Special literal none→ Indicate absence of value.
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.
DATA TYPES IN PYTHON:-
1- Numbers:
1- Integer. ↓
Boolean.
2- Floating point.
3- Complex.
2- Sequence:
1- Strings.
2- Lists.
3- Tuples.
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.
<Compound statement header>
<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.
The ‘if’ statement:
The if conditionals of python come in multiple form:
plan if conditional
if-else conditional and if-else conditional
Nested if statement:
A nested if is an if that has another if in it’s if’s body or in elif’s body or in it’s else’s body.
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
The for loop:
The for loop of python is designed to process the items of any sequence, such as a list or a string, one
by one.
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 break statement:
A break statement skips the rest of the loop and jumps over to the statement following the loop.
The continue statement:
The continue statement skips the rest of the loop statements and causes the next iteration of the
loop to take place:
Loop else statement:
Python loop has an optional else.
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”
Name[0]=’p’(will cause an error)
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)
String concatenate operator:
The + operator creates a new string by joining the two operand string.
String replication operator:
print(“hello”*3)
result: hello hello hello
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.
Determining ASCII/Unicode value of a single character:
Python offers a built in function ord() that take a single character and return a corresponding ASCII
value or Unicode.
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)