Python Note Score
Python Note Score
PYTHON
PROGRAMMING
This notebook includes:
JavaScript React
UI Libraries &
Vue
Frameworks Angular
Python jQuery
Django
Python
Flask Technologies
Node.JS SQL
Oracle
Database MySQL
MongoDB
Git/Github
VScode Tools and Cloud
Hosting
AWS
Azure/GC
rh22
Introduction :-
Python is a high-level interpreted programming language.
It is used in many areas.
Like-
• Software development
• Web development
• Software testing
• Machine learning
• Data Science
• Game development
• App development
History of Python :-
Python was developed by Guido Van Rossum in the Year 1990. At Centrum in the
Netherlands as a successor of a language called ABC.
Name “Python” picked from TV show Monty python’s flying circus.
Version :-
• Python 0.9.0 February 1991
• Python 1.0 January 1994
• Python 2.0 October 2000
• Python 3.0 December 2008
• Python 3.12 October 2023(Latest)
•
Features :-
• Easy to learn
• High-level language
rh22
• Interpreted language
• Plateform independent
• Procedure & Object oriented
• Scalable & Huge library
Binary Output
Program code
Byte code
• Interpreter converts the byte code into machine code and sends that
machine code to the computer processor for execution.
rh22
Identifier :-
• An identifier is a name having a few letters, numbers and special
characters.
• It should always start with a non-numeric character.
• It is used to identify a variable, function, symbolic constant, class etc.
Reserved word :-
Python language uses the following keywords which are not available to
users to use them as identifiers.
Like- False, else, import, pass, yield…etc.
Constant :-
• There are no constants in python, the way they exist in c and java.
• In python, constants are usually defined on a module level and
written in all capital letters with underscores seprating words but
remember its value can be changed.
Variable :-
Data Type :-
Datatype represents the type of data stored into a variable or memory.
Types of Datatype :-
I. Built-in Data type-
• Integer:- In Python, integers are classified into zero, positive, or
negative whole numbers with no fractional part.
rh22
Examples-1,3,12,10….etc.
a=10,
b=23,
• Float:- The float data types are used to store positive and
negative numbers with a decimal point.
Examples- 2.3, 2.22, 5.8…etc.
Operator :-
An operator is a symbol that performs an operations.
Types of operators-
• Arithmatic operator
Like- +, -, *, /, %, **, //
• Logical operator
Like- and, or, not
• Assignment operator
Like- =, +=, -=, *=, %=, **=, //= ….etc.
rh22
• Bitwise operator
Like- &, |, <<, >> …etc.
• Membership operator
Like- in, not in
• Identity operator
Like- is, is not
Type conversion:-
Converting one data type into another data type is called type conversion.
Escape sequence:-
Escape sequences are control character used to move the cursor and print
characters such as ‘,’’ and so on
This function will stop the program flow until the user gives an input and end the
input with the return key.
Syntax-
Input(“Enter your message….”)
Condition Statements:-
• If statement- It is used to execute an instruction or block of instructions
only if a condition is fulfilled.
Syntax-
If condition:
Statements….
Statements….
• If elif statement-To show a multi-way decision based on several conditions,
we use if elif statement.
Syntax-
If condition:
Statements….
elif condition:
rh22
Statements….
elif condition:
Statements….
If condition:
If condition:
Statements…
else:
Statements…
else:
Statements….
Control statements:-
Loops- Repeation of task is called loop.
Types of loop-
• While loop- The while loop keeps repeating an action until an associated
condition returns false.
Syntax-
While condition:
Statements….
• For loop- The for loop is useful to iterate over the elements of sequence
such as string, list, tuple etc… Syntax- for I in sequence:
Statements….
Break statements:-
Break statement is used to jump out of loop to process the next statement in the
program. Syntax-
Break
Continue statements:-
Continue statement is used in a loop to go back to the beginning of the loop.
Syntax-
Continue
rh22
Pass statements:-
Pass statement is used to do nothing. It can be used inside a loop or if statement
to represent no operation.
Pass is useful when we need statement syntactically correct but we do not want
to do any operation.
Syntax-
Pass
Array:-
Collection of similar datatype is known as array.
In python, arrays can increase or decrease their size dynamically.
Array uses less memory than list.
We have to import array module for use array in python.
Note- Python does not support multi-dimensional array but we can create
Multidimensional array using third party packages like numpy.
Syntax-
Import array
array_name=array.array(‘type_code’,[element])
Eg-
Import array
roll=array.array(‘ I ’,[11,12,13])
for i in range(len(roll)):
print(roll[i])
rh22
Pip:-
Pip is the package manager for python.
Using pip we can install python packages.
• title()- It is used to convert the string in such that each word in string will
start with a capital letter and remaining will be small letter.
Syntax-
Stringname.title()
• isdigit()- It returns True if the string contains only numeric digits(0 to 9) else
returns False.
Syntax-
Stringname.isdigit()
• isalpha()- It returns True if the string has at least one character and all are
alphabates (A to Z and a to z) else returns False.
Syntax-
Stringname.isalpha()
• isalnum()- It returns True if the string has at least one character and all
characters in the string are alphanumeric (A to Z, a to z and 0 to 9) else
returns False.
Syntax-
Stringname.isalnum()
• isspace()- It returns True if the string contains only space else returns False.
Syntax-
Stringname.isspace()
• lstrip()- It is used to remove the space which are at left side of the string.
Syntax-
Stringname.lstrip()
rh22
• rstrip()- It is used to remove the space which are at right side of the string.
Syntax-
Stringname.rstrip()
• strip()- It is used to remove the space from the both side of the string.
Syntax-
Stringname.strip()
Syntax-
def fun_name():
statements…. Function definition
deffun_name(para1,para2,….):
statements….
fun_name() calling
fun_name(para1,para2,…)
Types-
Advantages-
• Code reusability
• Ease of code maintainance
• Easy to debugging
rh22
Example-
def add(y):
x=10
c=x+y
return c
sum=add(20)
print(sum)
Examples-
II. Keyword arguments- These arguments are passed to the function with
name_value pair so keyword arguments can identify the formal arguments
by their names.
The keyword argument’s name and formal argument’s name must match.
Example-
def show(name,age):
print(name,age)
show(name=”henni”,age=22) or
show(age=22,name=”henni”)
• It can only contain expression and can’t include statements in its body.
• You can use all the type of actual arguments.
• In lambda function there is no need to write return statement.
Syntax-
lambda argument_list: expression
Example-
lambda x: print(x)
a=add()
print(a)
print(a(20))
Local variable- The variable which are declared inside a function called as local
variable.
Local variable scope is limited only to that function where it is created.
Eg-
def add():
x=20 local variable
print(x)
Global variable- When a variable is declared above a function, it becomes global
variable.
This variables are available to all the function which are written after it.
The scope of global variable is the entire program body written below it.
Eg-
a=60 global variable
def show():
x=20 local variable
Global keyword- If local variable and global variable has same name then the
function by default refers to the local variable and ignores the global variable.
In this situation, if we need to access global variable inside the function we can
access it using global keyword followed by variable name.
Eg-
i=60
def
show():
global i=60 creation global variable
i=i+1
print(i)
print(i)
rh22
Global function- This function returns a table of current global variables in the
form of dictionary.
Recursion- A function calling itself again and again to compute a value is
referred to recursive function or recursion. Eg-
def fun():
print(“henni”)
fun() calling itself
fun()
• append()-
• insert()-
• pop()-
• remove()-
• index()-
• reverse()-
• extend()-
• count()-
• sort()-
• clear()-
• list()-
Some important note about tuple-
• we can not delete an element of a tuple. We can delete tuple using del
keyword.
Syntax-
del tuple_name
• we can not take a direct tuple input from user. We take a list input from
user and after that convert into tuple.
rh22
THE END
Instagram_id :- rising_harmony22
By-heni