Introduction To Programm Ing Language
Introduction To Programm Ing Language
Types of programming language: Low level, High level and middle level
High level: procedure (it has routine and structure like C, FORTAN etc)
object (it uses instance or objects or entity, to reuse code, it is faster and
easier to execute, maintain) and natural language(Python, Java, Java
script)(used perform tasks such as translation, automatic
summarization .Can used any human language. Used to understand,
manipulate and interpret human language). To develop user friendly
software programs and websites. Python is natural language)
Low level: Machine language, Assembly language.(represents the set of
instructions in a symbolic and human understandable form).It is machine
dependent without ned of interpreter or compiler, so the program can be
written fast
Middle level: C++ , also known as pseudo Language (false code to form
code ).It supports features of high level language.
VALUABLE DECLARATION
print(myNumber)
Rules to declare as variable :
The variable must star with aletter or the underscore
It cannot start with a number
It can only contain alpha numeric character and underscores
They are case sensitive
#declaring the var Number = 100
#display print(Number)
Berfore and after declare function changes the value
Eg : Number = 100
print("Before Declare: ", Number)
Number = 120.2
print("After Declare: ", Number)
Data types are : numeric( integer , float) , dictionary, Boolean, set and sequence
type(strings and tuple)
In python, all datatypes types are known as classes
The values for datatypes are instance or object ( a =10)
The w that data items are caterogizd or classified is known as their data
type.
It stands for the type of value that indicates the types of operations that
can be carried out on a specific type of data.
PYTHON TYPE FUNCTION : to define the values of various data types
and check their data types we use the type function
Eg : a = 150
print("The type of variable having value", a, "is ", type(a))
The type of variable having value 150 is <class 'int'>
c = 18+3j
print("The type of variable having value", c, "is ", type(c))
The type of variable having value (18+3j) is <class 'complex'>.
Run : This is me
This is two
{'name': 'christ-MDC', 'code': 1234}
KEYWORDS
Eg : importkeyword
print("The list of keyword is : ")
print(keyword.kwlist)
Creating stringes
Eg: String1 = '''Christ
For
Life'''
print("\nCreating a multiline String:")
print(String1)
Run : Creating a multiline String:
Christ
For
Life
Eg: String1 = "I Love Icecream"
print("Intial string:")
print(String1)
x = "Poppy Flower"
x = "".join(reversed(x))
print(x)
Run: UOI
rewolF yppoP
String Slicing:
Eg: x = "Poppy Flower"
print("\nSlicing characters from 3-9:")
print(x[3:9]) #slicies after 3 and before 9
Run: Slicing characters from 3-9:
py Flo
Eg: x = "Poppy Flower"
print("\nSlicing characters from 3 to -2:")
print(x[3:-2]) #slicies after 3 and before 9
Run: Slicing characters from 3 to -2:
py Flow
list1 = list(x)
list1[2] = 'p'
String2 = ''.join(list1)
all function
Returns true if all elements are true
Eg: mylist = [True, True, False , True] #the words should be same for true
x = all(mylist)
print(x)
Run: False
any function
Eg: mylist = [True, True, False , True]
x = any(mylist)
print(x)
Run: True
Len function
Eg: mylist = [True, True, False ]
x = len(mylist)
print(x)
Run: 3
Sort:
x = [3, 5,4,2,]
x.sort()
print(x)
Run: [2, 3, 4, 5]
Extend:
x = [3, 5,4,2,]
x.extend("l")
print(x)
Run: [3, 5, 4, 2, 'l']
Insert:
= [1, 3,4,6,7]
x.insert(2,"k")
print(x)
Run: [1, 3, 'k', 4, 6, 7]
Delete:
x = [1, 3,4,6,7]
del x[1]
print(x)
Run: [1, 4, 6, 7]
x = [1, 3,4,6,7]
del x[:2]
print(x)
Run: [4, 6, 7]
Remove:
x = [1, 3,4,6]
x.remove(6)
print(x)
Run: [1, 3, 4]
Reverse:
x = [1, 3,4,6]
x.reverse()
print(x)
Run: [6, 4, 3, 1]
OOPS CONCEPT
Object oriented programming language is to design the program using
classes and objects like book, house, pencil etc.
Can reuse the function or code to reduce size
Eg: x = obj.sub(6,3) [function declaration]
print(x) [function definition]
obj is [function calling]
Procedural programming uses a list of instructions to do computation
while object-oriented uses problem solving approach where computation
is done using objects
Major principles are: Class, Object, Method, Inheritance (extract same
property), Polymorphism, Data Abstraction, Encapsulation
Class is a collection of objects. Contains attributes and method (name,
age and salary) for class of employee.
Object has a state and behaviour. May any real-world object like pencil,
table
Method is associated with object and unique to a class instance like add
Inheritance is the child object inherits the behaviours and properties of
parent object. Class can use all the properties and behaviours of another
class.
Derive class is taken from base class. It represents real world
relationships well and provides reuseability. Less development and
maintenance expenses.
When a derived class is inherited from two or more higher classes it is
called multi level inheritance
When a derived class is inherited from multiple base classes in the same
level, it is called multiple inheritance.
Polymorphism is same name multiple forms. For add function many
variables can be used.Can chane the value of a variable.
Eg: def add(x, y, z = 0):
return x+y+z
print(add(2,3))
print(add(2,3,4))
RUN:
5
9
Encapsualtion is the idea of wrapping data and the methods that works
on data within one unit,Prevents accidental modification of data and puts
restrictions on accessing variables.
Private data can only be modified in that program using the given
method/ object only
Protected data cannot be accessed outside the class only within the class
and its subclass.Use “_”
All class definitions start with the class keyword, which is followed by
the name of the class and a colon.
The python __init__ method is declared within a class and is used to
initialize the attributes of an object as soon as the object is formed.
Eg: class Myclass:
def __init__(self, name, age):
self.name = name
self.age = age
def display_info(self):
print(f"Name: {self.name}")
print(f"Age: {self.age}")
obj = Myclass("John", 25)
obj.display_info()
RUN:
Name: John
Age: 25
EXCEPTIONS
Errors or mistakes in program are often referred to as bugs.They are almost
always the fault of the programmer.The process of finding and eliminating
errors is called debugging. They are classified into three major groups:
Syntax, Runtime and Logical errors.
Tkinter
Looping : It requires count, action(increase) and intital value
Eg : Count = 1
While count <= 5
Print(python)
Count = count + 1
import tkinter as tk
root = tk.Tk()
count = 1
while count <= 5:
label = tk.Label(root,text = "Hello")
label.pack()
count = count + 1
root.mainloop()
Run ;
import tkinter as tk
root = tk.Tk()
count = 1
while count <= 5:
label = tk.Label(root,text = "Hello" , bg= "Orange")
label.pack()
count = count + 1
root.mainloop()
Run :
import tkinter as tk
root = tk.Tk() #for creating a window
count = 1
while count <= 5:
label = tk.Label(root,text = "Hello" , bg= "Orange" , fg = "white")
label.pack()
count = count + 1
root.mainloop()
Run:
Tk.lable for making label in tk
Tk.entry for entering username
Label 2 is password heading
Tk.entry 2 is entering password
Login button is a button
Eg: import tkinter as tk
root = tk.Tk()
root.title = "Log in"
Label1 = tk.Label(root, text="username")
Label1.pack()
Entry1 = tk.Entry(root)
Entry1.pack()
Label2 = tk.Label(root, text="password")
Label2.pack()
Entry2 = tk.Entry(root)
Entry2.pack()
Button1 = tk.Button(root, text="LOGIN")
Button1.pack()
root.mainloop()
Run ;
Eg : deflogin_click():
username = Entry1.get()
password = Entry2.get() #stores username and password
if username =="Riya" and password =="2888":
messagebox.showinfo("sucess")
else:
messagebox.showinfo("faliure")
def cancel_click():
messagebox.showinfo("Redirecting to homepage")
Label3 = tk.Label(root, text="Goodbye", bg="yellow", font="Mangal")
Label3.pack()
root = tk.Tk()
root.title = "Log in"
Label1 = tk.Label(root, text="username", font = "Cambria")
Label1.pack()
Entry1 = tk.Entry(root)
Entry1.pack()
Label2 = tk.Label(root, text="password", font = "Cambria")
Label2.pack()
Entry2 = tk.Entry(root)
Entry2.pack()
Button1 = tk.Button(root, text="LOGIN",command = login_click )
Button1.pack()
Button2 = tk.Button(root, text="Cancel",command = cancel_click)
Button2.pack()
root.mainloop()
Run:
Domain
NCRB Crime type classification by previous years
The list includes,[crime type], [numbers of type of crime reported
in 2021],[crime rate in 2021],[ numbers of type of crime reported
in 2022],[crime rate in 2022], [percentage of IPC]