15/6
ADVANCE PYTHON CONCEPTS
## Importance of Python
1) Python Environment
- Unix (Solaris, Linux, FreeBSD, AIX, HP/UX, SunOS, IRIX, etc.)
- Win 9x/NT/2000
- Macintosh (Intel, PPC, 68K)
2) Python library
- path :- /usr/local/lib/pythonXX
NOTE:- XX is version
3) Python in command prompt
- $python
- python%
- C:> python
## How to create script file in python
- In Unix: $python script.py
- In Window: C: >python script.py
## Python IDE(Integrated Development Environment)
- Unix −> IDLE is the very first Unix IDE for Python.
- Windows −> PythonWin is the first Windows interface for Python and is an IDE with a GUI.
## Python Interpreter
- Similar to compiler just like C.
## Python Error Handling
- Error Handling is use to exception concept
1) System Exit
2) Standard Error
3) Arithmatic Error
4) Overflow Error
5) Zero Division Error
6) Eof Error
7) Keyboard Interrupt Error
8) Key Error
9) IO Error
10) Syntax Error
11) Value Error
## Python Expression
- A regular expression is a special sequence of characters that helps you match or find other strings or sets of strings.
1) Pattern
2) String
3) Flag (true and false)
ex:- email matching , mobile no matching
## Python Email Programming
- SMTP(Simple Mail Transfer protocol) object
- Message object
IMPORTANT
### XML(Extensible Markup Language) working in python
- XML is a temporary file
Two concepts:-
1) XML object
2) Document object
MOST IMPORTANT
## Python GUI(Graphical User Interface) Programming
- Developing the form and control
** Tkinter Programming
** wxPython
** JPython
## Python tools and utility
- The dis Module
17/6
## Object Oriented in Python
- Object Oriented based on class structure.
## What is class?
- Collection of member or method
- Member is also called as variable
- Methods are called functions
## How to create a class.
Syntax:-
class class_name:
member or function
## How to create a member function
Syntax:-
def __init__(self,member):
execute the logic
NOTE:-
- To call class we create an object
- Here we apply _ 2 times
ex.
class car:
def __init__(self,name): //member defined
self.name=name // storing member
def display(self): // function created
print(self.name) // printing main member
c1 = car("Swift") //created object and passed parameter
c1.display() //called the display()
output:- Swift
## How to use member
- Member is also called variable
ex.
class my:
id=10
def display(self):
print(self.id)
num=my()
num.display()
output:- 10
## Constructor
- Constructor is called only once at the time of creating an instance.
- If two instances are created for a class, the constructor will be called once for each instance.
- Class name and definition name are similar
- We don't create function here
ex.
class student:
def __init__(self):
print("This is my First program.")
s1=student()
output:-
This is my First program.
Types:-
1) Non - parameterized constructor
ex.
class student:
def __init__(self):
print("This is my First program.")
s1=student()
output:-
This is my First program.
2) Parameterized constructor
ex.
class student:
def __init__(self,name):
print("This is parameterized constructor.")
self.name=name
def show(self):
print(self.name)
s1=student("Ajay")
s1.show()
Output:-
This is parameterized constructor.
Ajay
TASK:-
Create prgm using user input
class student:
def __init__(self):
self.fname=input("Enter the first name: ")
self.lname=input("Enter the last name: ")
def show(self):
print("Hello " + self.fname + ' ' + self.lname)
s1=student()
s1.show()
Output:-
Enter the first name: tina
Enter the last name: roy
Hello tina roy
21/6
## How to find no. of objects in constructor
ex.
class student:
count=0
def __init__(self):
student.count=student.count+1
s1=student()
s2=student()
s3=student()
s4=student()
print("The no. of object", student.count)
output:-
The no. of object 4
count statement counting the object
## Types of constructor
1) Default constructor
- Inside bracket we use self
ex. def display(self)
- self ==> read itself
ex.
class student:
name="Mohan"
def display(self):
print(self.name)
f1=student()
f1.display()
output:- Mohan
2) Parameterized Constructor
3) Non-parameterized constructor
IMPORTANT
## Inheritance
- Reusability of class
- Parent class does not use properties of derived class
- Python does not support multiple inheritance.
1) this class
2) derived class
IMP NOTE - Create a last class object
Syntax:-
class derived_class_name(base_class_name):
ex.
class base:
def display(self):
print("This is a display function.")
class derived(base):
def show(self):
print("This is a show function.")
d1=derived()
d1.show()
d1.display()
output:-
This is a show function.
This is a display function.
TASK:-
1) Using parameter inheritance
ex.1:-
class headoff:
def display(self):
print("This is a display function.")
class branchoff(headoff):
def show(self,empname):
self.empname=empname
print("This is a show function. Employee name is " +self.empname)
d1=branchoff()
d1.show("Varun Sharma")
d1.display()
output:-
This is a show function. Employee name is Varun Sharma
This is a display function.
ex.2:-
class headoff:
def display(self,empname):
self.empname=empname
print("This is a Head Office. Employee name is " +self.empname)
class branchoff(headoff):
def show(self):
print("This is a Branch Office.")
d1=branchoff()
d1.show()
d1.display("Varun Sharma")
output:-
This is a Branch Office.
This is a Head Office. Employee name is Varun Sharma
2) Multilevel Inheritance using user input
25/6
IMP POINTS TO REMEMBER:-
- Python interpreter is in the settings under Project:mypy(directory name)
-- Select python interpreter to execute the prgm if interpreter error occurs.
30/6
## HTML file in PyCharm editor
File menu ==> new project ==> select html file option ==> create a directory ==> click on create button
Create html file ==> click on file menu ==> new ==> select html file option ==> give name and enter
NOTE:- Bydefault PyCharm works on localhost.
TASK:-
1) All html tag implement
a) iframe tag
b) form tag
c) div tag
d) frameset tag
e) anchor(a href) tag(whatappme concept)
f) img tag
2) Internal CSS implement
3) JavaScript implement
a) JavaScript statements
b) JavaScript form concept ==> textbox no. addition, radio button list, button event
c) JavaScript validation
d) if, while, do, for
2/7
## File Handling using Python
- Collection of information in systematic format is called file.
## Types of file:-
1) System file--reads system file, exe file, OS file
2) User file
## File Mode
1) W mode (write)
2) A mode (append)
3) R mode (read)
## File Object in python
- File Object is used to create a file using python.
- There are following function used in python file handling
1) Open()
2) Write()
3) Read()
4) Close()
Syntax:-
fileobject=open("filename","mode")
## How to create a file
ex.
f=open("my.txt","w")
print("File created.")
NOTE:-
f is file object. We can give any name.
## How to write data in a file
f=open("my.txt","a")
f.write("This is my first file handling program.")
f.close()
print("Write successfully.")
NOTE:- We can write 'w' instead of 'a', it'll also write the text in file.
## How to read a file
f=open("my.txt","r")
print(f.read())
## How to read file from specific location
f=open("e:\\my.txt","r")
print(f.read())
TASK:-
- File handling using user input
x=input("Enter any text ")
v=open("vidya.txt","w")
v.write(x)
Comments
Post a Comment