[go: up one dir, main page]

0% found this document useful (0 votes)
40 views22 pages

Introduction To Programm Ing Language

The document discusses different types of programming languages including low level, high level and middle level languages. It also describes different data types in Python like numeric, string, list, tuple, range, dictionary and set. It covers concepts like variables, operators, conditional statements.

Uploaded by

helna sebastian
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views22 pages

Introduction To Programm Ing Language

The document discusses different types of programming languages including low level, high level and middle level languages. It also describes different data types in Python like numeric, string, list, tuple, range, dictionary and set. It covers concepts like variables, operators, conditional statements.

Uploaded by

helna sebastian
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 22

INTRODUCTION TO PROGRAMMING LANGUAGE

 Language is a mode of communication that is used to share ideas


opinions with each other,
 A programming language is a computer language that is used by
programmes to communicate with computers.It is a set of instructions
written in any specific language (python) to perform a specific task
 It is used to develop desktop applications, website and mobile
applications.
 C is mother language of a software.It is a middle level language. And
procedural oriented language.
 C++ is object oriented
 Hybrid language is a mix of above both.Eg: SQL Database
 Integer is a keyword, float ( decimals ) is a keyword , string(words 0 is a
keyword.

 Desktop :No requirement of netwok .Software derived from already


stored database

 Network : HTML. Only for web page design

 Mobile : Android or IOS. All content in single device.

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

 Variable is a name for some information. Eg: Name = jay , x = 10


 Used for the identification of the value
 A python is a name given to a memory location.It is the basic unit of
storage in a program
 Eg : myNumber(variable) = 3(value) cumdc = 60
 print (myNumber)
CUMDC = 2
 myNumber2 = 4.5
cu_m_dc = 5
 print(myNumber2)
 myNumber ="helloworld" _cumdc = 6

 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)

 python allows assigning a single value to several varibales


Eg : a = b= c =10
print (a)
print (b)
print (c)
 Python can assign diff values to multiple variables using comma (,)
a, b, c = 1, 2, “Clouds”
print(a)
print(b)
print(c)
 The python plus operator + to add a value and concanatate the words if it
is a string. The sum or concate goes to the same variable.
Eg : a = 10
b = 321
print(a + b)
a = "Dona "
b = "Says Hi"
print(a +b)

 There are two variables – global and local variable


 Global is used outside the function while local is outside the function

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'>.

 Gives us the name of the value as a data type class name


 STRING DATA TYPE : A group of one or more characters enclosed in a
single, double or triple quote is called a string in python
 A character in python is just a string with a length of one string
 The str class is used to represent it.
 First letter in string has value of 0 ( index number ) and so on.Sometimes
space has value
Eg : str='Hello world '
print(str)
print (str[3])
print(str[2:5])
print (str[2:])
print(str + "TODAY !")
print(str * 2)
 Run :
 l
 llo
 llo world
 Hello world TODAY !
 Hello world Hello world

 List data type : it is an arranged grouping in the same or dissimilar


elements(numbers and words) that area enclosed within the brackets and
separated by commas
 Use the index number to retrieve the list entries
 To acess a particular item in list, use the index operator []
Eg : list= ['abcd', 786,65.44,'See-SAW', 70.2]
tinylist = [123, 'python']
print(list)
print(tinylist * 3)
print(list[0])
print(list[1:3])
print(list + tinylist)
Run :
['abcd', 786, 65.44, 'See-SAW', 70.2]
[123, 'python', 123, 'python', 123, 'python']
abcd
[786, 65.44]
['abcd', 786, 65.44, 'See-SAW', 70.2, 123, 'python']
*(note : after index number 1 the numbering is done according to positions not
index numbers)
Eg : print(list[1:5])
 [786, 65.44, 'See-SAW', 70.2]

 Tuple is an orders list of elements just like a list


 tuples a re not changeable (immutable) during operation time
 tuples are stored using ()
 curly brackets come for dictionary
 we utilize index number to retrive tuple items
 parathesis comes in output
Eg : tuple= ('abcd', 786,65.44,'See-SAW', 70.2,)
tinytuple = (123, 'python')
print(tuple)
print(tinytuple * 3)
print(tuple[2])
print(tuple[1:4])
print(tuple + tinytuple)
 Run : ('abc', 786, 65.44, 'See-SAW', 70.2, 'hi')
(123, 'python', 123, 'python', 123, 'python')
65.44
(786, 65.44, 'See-SAW')
('abc', 786, 65.44, 'See-SAW', 70.2, 'hi', 123, 'python')

 Range datatype : range() in python is a built in function that returns a


series of numbers that begin at 0 and increase by 1 until they reach a
predetermined number.
 We used it to produce a series of numbers utilizing for and while loop
Eg : for i in range(1,5):
print(i)
Run :
C:\Users\helna\PycharmProjects\pythonProject\.venv\Scripts\python.exe C:\
Users\helna\PycharmProjects\pythonProject\main.py
1
2
3
4
 Python dictornary type : It is an unorderd collection of dsara values that is
used to store dta values in a map like function
 Dictionaries conatin a key - value pair
 A colon : separtes the key and value\
 Can be made enclosing in curly braces {} and separting using commas
Eg : dict= {}
dict ['one'] = "This is me"
dict[2] = "This is two"
tinydict = {'name':'christ-MDC','code':1234}
print(dict['one'])
print(dict[2])
print(tinydict)

Run : This is me
This is two
{'name': 'christ-MDC', 'code': 1234}

 Python set data type : A set is unsorted collection of distinct components.


 It is changeable (mutable)
 They cannot be repeated
 Curly brackets used
Eg : my_set= {1, 2, 3, 4, 5}
print(my_set)
Run : {1, 2, 3, 4, 5}

KEYWORDS
Eg : importkeyword
print("The list of keyword is : ")
print(keyword.kwlist)

Run : he list of keyword is :


['False', 'None', 'True', 'and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del',
'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda',
'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']
OPERATERS
In Python programming, Operators in general are used to perform operations on
values and variables. These are standard symbols used for the purpose of logical
and arithmetic operations.
OPERATORS: These are the special symbols. Eg- + , * , /, etc.
OPERAND: It is the value on which the operator is applied.
Types of Operators in Python
Arithmetic Operators - ( +, -. / , *) as well as percentage and power (**)
 Parenthesis, exponentiation , Multiplication,Divion.Addition,Subtraction
Comparison Operators - >,<,=, !=(not equal to)
Logical Operators – and, or, not ( and – check if both are true, or – checks if
either is true , not a – finds opposite of a)
Bitwise Operators – checks if in binary language if given numbers are both
either
1 0 0 0 0
2 1 0 0 0
3 0 1 0 0
4 1 1 0( 4 times 0
each)
5 0 0 1 0 ( 8 times

5 – binary value in five digits - 0010


 & checks if the binary foerms corresponds with each other in the same
position for 1, if 1 results is 1 if not corresponding for 1 , result is 0
Assignment Operators - a = 3
b = 5
a += b
print(a)
Run= 8
Identity Operators and Membership Operators (FIND DEFINE)
 Nested if statement : If statement inside if statements
 Identation is imp to figure out the level of neating
 Eg :
 a = 2
if a >= 0:
if a == 0:
print("zero")
else:
print("positive")
else:
print("negative")
Run: positive
#Note that the if and else statements must be in the l=same lines to produce
result
Eg:
p = 15
if p == 15:
print("p is equal to 15")
if p > 12:
print("p is greater")
else:
print("p is lesser")
else:
print("p is not equal to 12")
Run: p is equal to 15
p is greater
#Note the first if statement must b e true to read the next one
eg: a = 12
b = 10
if a > b:
print("a is greater than b")
if b >= 10:
print("b is equal to ten")
else:
print("b not equal")
else:
print("a is less")
Run : a is greater than b
b is equal to ten
Looping
 All loops start with a syntax
 For(Keyword always present in syntax) iterative variable(x) in(Keyword)
sequence name(colour) :
 If the condition given is met the loop repeats and when the condition
becomes falses in the end , the command is exited.

Eg : colour= ["Red", "Green", "Blue"]


for x in colour :
print(x)
Run :
 Red
 Green
 Blue

To print letter by letter


Eg: letter = "RED"
for x in letter :
print(x)
Run :
 R
 E
 D

To print set of numbers- Eg : for x in range(5):


print(x)
Run :
 0
 1
 2
 3
 4
To print a set of numbers without zero – Eg: for x in range(1,5):
print(x)
 Run:
 1
 2
 3
 4
To print temperature range – Eg: for x in range(-2,1):
print(x, "Celisus")
Run :-2 Celisus
-1 Celisus
0 Celisus
To print addition of numbers – Eg: nums
= (1,2,3,4,5)
sum_nums = 0
for num in nums:
sum_nums = sum_nums + num
print(f'Sum of numbers is {sum_nums}')
Run : Sum of numbers is 1
Sum of numbers is 3
Sum of numbers is 6
Sum of numbers is 10
Sum of numbers is 15

Entry and exit control loop


 Entry control loop is for and while
 Exit control loop checks the conditional executes
BREAK AND CONTINUE LOOP
 Breaks for skipping the looping statement
 From that statement break happens
 Continue statement used to flow the loop
 Executes only within the condition to check the condition
Eg : fori in range(5):
if i == 3:
break
print(i)
 Run :
 0
 1
 2
Note when I = 3 , the loop breks and shows only till 2
Eg: i = 0 #here when I less than 5 and not equal to 3 it prints I +1 and
loops back the anwer the the beginning and checks the condition again with
I +1 , now equal to 1
while I < 5:
if I == 3:
break
print(i)
I += 1
 Run : 0
 1
 2 ( breaks when the answer becomes 3
Continue statement
 Continue skip the current iteraton and proceed to next one
Eg: for i in range(5):
if i == 3: #skips over 3
continue
print(i)
 Run: 0
 1
 2
 4
Eg: i = 0
while i < 10:
i += 1 #adds and if the number formed is divisible by 2 , skip it
if (i % 2) == 0:
continue
print(i)
Run:
 1
 3
 5
 7
 9

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)

print("\n First letter of string:")


print(String1[0])

print("\n Last letter of string:")


print(String1[-1])
Run: Intial string: I Love Icecream
First letter of string:
I
Last letter of string:
M

Reversing a python string:


 Use [::-1] or x = "".join(reversed(x))
Eg: String1 = "IOU"
print(String1[::-1])

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

Deleting/updating from the string


 This is not allowed in python
 This will cause an error
 The elements cannot be change but the new strings can be reassigned to
the same name.
 Eg:substituting a letter
 x = "Hello i would like tea"
print("initial string:")
print(x)

list1 = list(x)
list1[2] = 'p'
String2 = ''.join(list1)

print("Updating character at 2nd Index:")


print(String2)

String3 = x[0:2] + 'p' + x[3:] #same as before function but wriiten


in different way
print(String3)
 Run: initial string:
 Hello i would like tea

 Updating character at 2nd Index:


 Heplo i would like tea
 Heplo i would like tea

Updating entire string


Eg: x = "Hello, I want tea"
print("initial string:")
print(x)
x = "I want milkshake"
print("\nUpdated string:")
print(x)
Run:
initial string: Hello, I want tea
Updated string: I want milkshake

Acess element from list


Eg : List= ["Gina", 2341123 , 18 , "BA Political Science"]
print("n\List with string:")
print(List[0])
print(List[1])
print(List[2])
print(List[3])
RUN: n\List with string:
Gina
2341123
18 BA Political Science
Eg: List = ["Gina", 2341123 , 18 , "BA Political Science"]
print("n\List with string:")
print(List[-3])
print(List[-1])
print(List[-2])
Run: n\List with string:
2341123
BA Political Science
18

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

LIST OPERATIONS AND TUPLES


 Mutable operations – alters or modifying their previous definition
 Append :
 x = [1,2,3]
x. append('h')
print(x)
 Run: [1, 2, 3, 'h']

 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: import tkinter as tk


from tkinter import messagebox
def login_click():
username = Entry1.get()
password = Entry2.get() #stores username and password
if username =="Riya" and password =="2888":
messagebox.showinfo("sucess")
else:
messagebox.showinfo("faliure")
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",command = login_click )
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]

You might also like