Python Tutorial For Beginners
Python Tutorial For Beginners
2. Learn JavaScript In One Video In
Chapter – 0 Hindi (2018)
What is Programming? Free YouTube Video
Just like we use Hindi or English to communicate with each other, we use a Programming language Python to
communicate with the computer.
3. Python Tutorial For Beginners In
Programming is a way to instruct the computer to perform various tasks. Hindi (With Notes)
Free YouTube Video
What is Python?
Python is simple and easy to understand language which feels like reading simple English. This Pseudo code nature of
4. Python Programming Course in
Python makes it easy to learn and understandable for beginners. Hindi (Advanced)
Free YouTube Video
Features of Python:
Easy to understand = Less development time
Free and open source 5. Web Scraping Tutorial using
High-level language Python and BeautifulSoup
Portable – works on Windows/Linux/Mac Free YouTube Video
Geektrust.in Open
Execute this file (.py file) by typing python hello.py and you will see Hello World printed on the screen.
Modules
A module is a file containing code written by somebody else (usually) which can be imported and used in our programs.
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:
We can use python as a calculator by typing “python” + TO DO on the terminal. [It opens REPL or read evaluation print
loop]
Comments
Comments are used to write something which the programmer does not want to execute.
Types of Comments:
a=30
b=”Harry”
c=71.22
https://codewithharry.com/videos/python-tutorial-easy-for-beginners#resources 2/20
5/3/2021 Python Tutorial For Beginners In Hindi (With Notes) - Code With Harry
Data Types:
Primarily there are the following data types in Python:
1. Integers
2. Floating point numbers
3. Strings
4. Booleans
5. None
Python is a fantastic language that automatically identifies the type of data for us.
a = 71 #Identifies a as class<int>
learnbay.in OPEN
learnbay.in OPEN
Operators in Python
The following are some common operators in Python:
type function is used to find the data type of a given variable in Python.
a = 31
type(a) #class<int>
b = “31”
https://codewithharry.com/videos/python-tutorial-easy-for-beginners#resources 3/20
5/3/2021 Python Tutorial For Beginners In Hindi (With Notes) - Code With Harry
type(b) #class<str>
A number can be converted into a string and vice versa (if possible)
There are many functions to convert one data type into another.
… and so on
input() function
This function allows the user to take input from the keyboard as a string.
Note: The output of the input function is always a string even if the number is entered by the user.
Suppose if a user enters 34 then this 34 will automatically convert to “34” string literal.
https://codewithharry.com/videos/python-tutorial-easy-for-beginners#resources 4/20
5/3/2021 Python Tutorial For Beginners In Hindi (With Notes) - Code With Harry
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.
The index in a string starts from 0 to (length-1) in Python. In order to slice a string, we use the following syntax:
Negative Indices: Negative indices can also be used as shown in the figure above. -1 corresponds to the (length-1)
index, -2 to (length-2).
word = “amazing”
word = ‘amazing’
String Functions
Some of the mostly used functions to perform operations on or manipulate strings are:
len(‘harry’) #Returns 5
2. endswith(“rry”) : This function tells whether the variable string ends with the string “rry” or not. If string is “harry”, it
returns for “rry” since harry ends with rry.
3. count(“c”) : It counts the total number of occurrences of 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.
Escape Sequence Characters comprises of more than one character but represents one character when used within the
string.
https://codewithharry.com/videos/python-tutorial-easy-for-beginners#resources 5/20
5/3/2021 Python Tutorial For Beginners In Hindi (With Notes) - Code With Harry
<|DATE|>
The list can contain different types of elements such as int, float, string, Boolean, etc. Above list is a collection of
different types of elements.
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.
https://codewithharry.com/videos/python-tutorial-easy-for-beginners#resources 6/20
5/3/2021 Python Tutorial For Beginners In Hindi (With Notes) - Code With Harry
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]}
4. get(“name”) : returns the value of the specified keys (and value is returned e.g. “Harry” is returned here)
Sets in Python
Set is a collection of non-repetitive elements.
S.add(1)
S.add(2)
# or Set = {1,2}
If you are a programming beginner without much knowledge of mathematical operations on sets, you can simply look at
sets in python as data types containing unique values.
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”)
All these are decisions that depend on the condition being met.
In python programming too, we must be able to execute instructions on a condition(s) being met. This is what conditions
are for!
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”)
Quick Quiz: Write a program to print yes when the age entered by the user is greater than or equal to 18.
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.
https://codewithharry.com/videos/python-tutorial-easy-for-beginners#resources 9/20
5/3/2021 Python Tutorial For Beginners In Hindi (With Notes) - Code With Harry
'''
if (condition1):
#code
elif (condition 2):
#code
elif (condition 2):
#code
….
else:
#code '''
Important Notes:
“make a lot of money”, “buy now”, “subscribe this”, “click this”. Write a program to detect these spams.
4. Write a program to find whether a given username contains less than 10 characters or not.
5. Write a program that finds out whether a given name is present in a list or not.
6. Write a program to calculate the grade of a student from his marks from the following scheme:
90 – 100 -> Ex
80 - 90 -> A
70 – 80 -> B
60 – 70 -> C
50 – 60 -> D
<50 – F
7. Write a program to find out whether a given post is talking about “Harry” or not.
Loops make it easy for a programmer to tell the computer, which set of instructions to repeat, and how!
1. While loop
2. For loop
While loop
https://codewithharry.com/videos/python-tutorial-easy-for-beginners#resources 10/20
5/3/2021 Python Tutorial For Beginners In Hindi (With Notes) - Code With Harry
In while loops, the condition is checked first. If it evaluates to true, the body of the loop is executed, otherwise not!
If the loop is entered, the process of condition check and execution is continued until the condition becomes false.
An Example:
i = 0
while i<5:
print(“Harry”)
i = i+1
Note: if the condition never becomes false, the loop keeps getting executed.
Quick Quiz: Write a program to print the content of a list using while loops.
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
https://codewithharry.com/videos/python-tutorial-easy-for-beginners#resources 11/20
5/3/2021 Python Tutorial For Beginners In Hindi (With Notes) - Code With Harry
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
10. Write a program to print the multiplication table of n using for loop in reversed order.
https://codewithharry.com/videos/python-tutorial-easy-for-beginners#resources 12/20
5/3/2021 Python Tutorial For Beginners In Hindi (With Notes) - Code With Harry
When a program gets bigger in size and its complexity grows, it gets difficult for a programmer to keep track of which
piece of code is doing what!
A function can be reused by the programmer in a given program any number of times.
def func1():
print(“Hello”)
This function can be called any number of times, anywhere in the program.
Function call
Whenever we want to call a function, we put the name of the function followed by parenthesis as follows:
Function definition
The part containing the exact set of instructions that are executed during the function call.
Quick Quiz: Write a program to greet a user with “Good day” using functions.
A function can accept some values it can work with. We can put these values in the parenthesis. A function can also
return values as shown below:
def greet(name):
gr = “Hello” + name
return gr
If we specify name = “stranger” in the line containing def, this value is used when no argument is passed.
For Example:
def greet(name=’stranger’):
#function body
Recursion
Recursion is a function which calls itself.
https://codewithharry.com/videos/python-tutorial-easy-for-beginners#resources 13/20
5/3/2021 Python Tutorial For Beginners In Hindi (With Notes) - Code With Harry
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
The programmer needs to be extremely careful while working with recursion to ensure that the function doesn’t infinitely
keep calling itself.
***
** #For n = 3
A file is data stored in a storage device. A python program can talk to the file by reading content from it and writing
content to it.
https://codewithharry.com/videos/python-tutorial-easy-for-beginners#resources 14/20
5/3/2021 Python Tutorial For Beginners In Hindi (With Notes) - Code With Harry
Types of Files
Python has a lot of functions for reading, updating, and deleting files.
Opening a file
Python has an open() function for opening files. It takes 2 parameters: filename and mode.
open(“this.txt”, “r”)
Here, “this” is the file name and “r” is the mode of opening (read mode)
In order to write to a file, we first open it in write or append mode after which, we use the python’s f.write() method to
write to the file!
f = open(“this.txt”, “w”)
f.close()
With statement
https://codewithharry.com/videos/python-tutorial-easy-for-beginners#resources 15/20
5/3/2021 Python Tutorial For Beginners In Hindi (With Notes) - Code With Harry
The best way to open and close the file automatically is the “with” statement.
with open(“this.txt”) as f:
f.read()
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.
Objects of a given class can invoke the methods available to it without revealing the implementation details to the
user. #Abstraction & Encapsulation!
https://codewithharry.com/videos/python-tutorial-easy-for-beginners#resources 16/20
5/3/2021 Python Tutorial For Beginners In Hindi (With Notes) - Code With Harry
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
Note: Instance attributes take preference over class attributes during assignment and retrieval.
harry.attribute1 :
‘self’ parameter
harry.getSalary()
class Employee:
company = “Google”
def getSalary(self):
print(“Salary is not there”)
Static method
Sometimes we need a function that doesn’t use the self-parameter. We can define a static method like this:
__init__() constructor
For Example:
https://codewithharry.com/videos/python-tutorial-easy-for-beginners#resources 17/20
5/3/2021 Python Tutorial For Beginners In Hindi (With Notes) - Code With Harry
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:
Also, we can overwrite or add new attributes and methods in the Programmer class.
Type of Inheritance
1. Single inheritance
2. Multiple inheritance
3. Multilevel inheritance
Single Inheritance
Single inheritance occurs when child class inherits only a single parent class.
Multiple Inheritance
Multiple inheritance occurs when the child class inherits from more than one parent class.
Multilevel Inheritance
https://codewithharry.com/videos/python-tutorial-easy-for-beginners#resources 18/20
5/3/2021 Python Tutorial For Beginners In Hindi (With Notes) - Code With Harry
Super() method
Super method is used to access the methods of a super class in the derived class.
Class methods
A class method is a method which is bound to the class and not the object of the class.
@classmethod
def (cls, p1, p2):
#code
@property decorators
class Employee:
@property
def name(self):
return self.ename
if e = Employee() is an object of class employee, we can print (e.name) top print the ename/call name() function.
@name.setter
def name(self, value):
self.ename = value
These methods are called when a given operator is used on the objects.
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)
__str__() -> used to set what gets displayed upon calling str(obj)
https://codewithharry.com/videos/python-tutorial-easy-for-beginners#resources 19/20
5/3/2021 Python Tutorial For Beginners In Hindi (With Notes) - Code With Harry
__len__() -> used to set what gets displayed upon calling .__len__() or len(obj)
Write a method SalaryAfterIncrement method with a @property decorator with a setter which changes the value of
increment based on the salary.
4. Write a class complex to represent complex numbers, along with overloaded operators + and * which adds and
multiplies them.
5. Write a class vector representing a vector of n dimension. Overload the + and * operator which calculates the sum
and the dot product of them.
6. Write __str__() method to print the vector as follows:
7i + 8j + 10k
7. Override the __len__() method on vector of problem 5 to display the dimension of the vector.
If the player’s guess is higher than the actual number, the program displays “Lower number please”. Similarly, if the
user’s guess is too low, the program prints “higher number please”.
When the user guesses the correct number, the program displays the number of guesses the player used to arrive at
the number.
← Previous Next →
© 2020-2021 CodeWithHarry.com
Back to top | Privacy | Terms
https://codewithharry.com/videos/python-tutorial-easy-for-beginners#resources 20/20