Python Tutorial For Beginners In Hindi (With Notes) - Code With Harry
Python Tutorial For Beginners In Hindi (With Notes) - Code With Harry
Course Content
Hide
Hide Player
Player
Overview
1. Learn
Q&AHTML In One
Video
Free YouTube
Files
Video
Announcements
2. Learn JavaScript In
Python Tutorial For Beginners In Hindi (With
One Video In Hindi
(2018)Notes)
Free YouTube
Video
Chapter – 0
WhatTutorial
3. Python is Programming?
For
Beginners In Hindi
Just like we use Hindi or English to communicate with each
(With Notes)
other, we use a Programming language Python to
Free YouTube
communicate with the computer.
Video
Installation
Execute this file (.py file) by typing python hello.py and you
will see Hello World printed on the screen.
Modules
Pip
Pip is a package manager for python. You can use pip to
install a module on your system.
E.g. pip install flask (It will install flask module in your system)
Types of modules
There are two types of modules in Python:
Comments
Comments are used to write something which the
programmer does not want to execute.
Types of Comments:
Comment “””.
a=30
b=”Harry”
c=71.22
Data Types:
Primarily there are the following data types in Python:
1. Integers
2. Floating point numbers
3. Strings
4. Booleans
5. None
Operators in Python
The following are some common operators in Python:
a = 31
type(a) #class<int>
b = “31”
type(b) #class<str>
… and so on
input() function
This function allows the user to take input from the keyboard
as a string.
Chapter 3 – Strings
The string is a data type in Python.
String Slicing:
A string in Python can be sliced for getting a part of the string.
word = “amazing”
word = ‘amazing’
String Functions
Some of the mostly used functions to perform operations on
or manipulate strings are:
any character.
4. capitalize() : This function capitalizes the first character
of a given string.
5. find(word) : This function finds a word and returns the
index of first occurrence of that word in the string.
6. replace(oldword, newword) : This function replaces the
old word with the new word in the entire string.
<|DATE|>
List Indexing
A list can be index just like a string.
L1 = [7, 9, ‘harry’]
L1[0] – 7
L1[1] – 9
L1[70] – Error
List Methods
Consider the following list:
Tuples in Python:
A tuple is an immutable (can’t change or modified) data type
in Python.
Tuple methods:
a = (1, 7, 2)
a = (7, 0, 8, 0, 0, 9)
Syntax:
Dictionary Methods
Consider the following dictionary,
a = {“name”: “Harry”,
“from”: “India”,
“marks”: [92,98,96]}
Sets in Python
Set is a collection of non-repetitive elements.
S.add(1)
S.add(2)
# or Set = {1,2}
Properties of Sets
1. Sets are unordered # Elements order doesn’t matter
2. Sets are unindexed # Cannot access elements by index
3. There is no way to change items in sets
4. Sets cannot contain duplicate values
Operations on Sets
Consider the following set:
S = {1,8,2,3}
S = Set()
S.add(20)
S.add(20.0)
S.add(“20”)
Syntax:
'''
if (condition1): // if condition 1 is true
print(“yes”)
elif (condition2): // if condition 2 is true
print(“No”)
else: // otherwise
print(“May be”)
'''
Code example:
a = 22
if (a>9):
print(“Greater”)
else:
print(“lesser”)
Relational Operators
Relational operators are used to evaluate conditions inside if
statements. Some examples of relational operators are:
= = -> equals
<=, etc.
Logical Operators
In python, logical operators operate on conditional
statements. Example:
elif clause
elif in python means [else if]. if statement can be chained
together with a lot of these elif statements followed by an else
statement.
'''
if (condition1):
#code
elif (condition 2):
#code
elif (condition 2):
#code
….
else:
#code '''
Important Notes:
90 – 100 -> Ex
80 - 90 -> A
70 – 80 -> B
60 – 70 -> C
50 – 60 -> D
<50 – F
1. While loop
2. For loop
While loop
An Example:
i = 0
while i<5:
print(“Harry”)
i = i+1
For loop
A for loop is used to iterate through a sequence like list, tuple
or string (iterables)
l = [1, 7, 8]
for item in l:
print(item)
Example:
l = [1, 7, 8]
for item in l:
print(item)
else:
print(“Done”) #This is printed when the loop
exhausts!
Output:
Done
Example:
Example:
for i in range(4):
print(“printing”)
if i == 2: #if i is 2, the iteration is skipped
continue
print(i)
pass statement
pass is a null statement in python. It instructs to “Do nothing”.
Example:
l = [1, 7, 8]
for item in l:
pass #without pass, the program will throw
an error
*
***
**
*** for n = 3
def func1():
print(“Hello”)
Function call
Function definition
def greet(name):
gr = “Hello” + name
return gr
For Example:
def greet(name=’stranger’):
#function body
Recursion
Recursion is a function which calls itself.
factorial(n) = n * factorial(n-1)
def factorial(n):
if i == 0 or i == 1 : #Base condition which doesn’t
call the function any further
return i
else:
return n*factorial(n-1) #Function calling
itself
***
** #For n = 3
Types of Files
Opening a file
open(“this.txt”, “r”)
Here, “this” is the file name and “r” is the mode of opening
(read mode)
f = open(“this.txt”, “w”)
f.close()
With statement
The best way to open and close the file automatically is the
“with” statement.
with open(“this.txt”) as f:
f.read()
Score.
3. Write a program to generate multiplication tables from 2
to 20 and write it to the different files. Place these files in
a folder for a 13- year old boy.
4. A file contains the word “Donkey” multiple times. You
need to write a program which replaces this word with
###### by updating the same file.
5. Repeat program 4 for a list of such words to be
censored.
6. Write a program to mine a log file and find out whether it
contains ‘python’.
7. Write a program to find out the line number where python
is present from question 6.
8. Write a program to make a copy of a text file “this.txt”.
9. Write a program to find out whether a file is identical and
matches the content of another file.
Class
A class is a blueprint for creating objects.
Object
An object is an instantiation of a class. When class is defined,
a template(info) is defined. Memory is allocated only after
object instantiation.
Class Attributes
Example:
Class Employee:
company = “Google” #Specific to each class
harry = Employee() #Object instantiation
harry.company
Employee.company = “YouTube” #changing class
attribute
Instance Attributes
harry.name = “Harry”
harry.salary = “30K” #Adding instance attributes
harry.attribute1 :
‘self’ parameter
harry.getSalary()
class Employee:
company = “Google”
def getSalary(self):
print(“Salary is not there”)
Static method
__init__() constructor
For Example:
class Employee:
def __init__(self,name):
self.name = name
def getSalary(self):
#Some code…
harry = Employee(“Harry”) #Object can be instantiated
using constructor like this!
Syntax:
Type of Inheritance
1. Single inheritance
2. Multiple inheritance
3. Multilevel inheritance
Single Inheritance
Multiple Inheritance
Multilevel Inheritance
Super() method
Class methods
@classmethod
def (cls, p1, p2):
#code
@property decorators
class Employee:
@property
def name(self):
return self.ename
below:
@name.setter
def name(self, value):
self.ename = value
p1 + p2 -> p1.__add__(p2)
p1 – p2 -> p1.__sub__(p2)
p1 * p2 -> p1.__mul__(p2)
p1 / p2 -> p1.__truediv__(p2)
p1 // p2 -> p1.__floordiv__(p2)
7i + 8j + 10k
the number.
← Previous Next →
© 2020-2021 CodeWithHarry.com
Back to top | Privacy | Terms