JAIN HAPPY SCHOOL
CLASS 11( A+B)
SUBJECT-IP
CHAPTER-3
PYTHON FUNDAMENTAL
Python Fundamentals
Python Fundamentals
Python Fundamentals
Python Fundamentals
• These are the special symbols that help us in performing calculations
and manipulations on the data.
• The data on which operators work are called as operands.
• Python has vast variety of operators divided in different categories
depending upon the work done by them. These are
• Assignment Operators ( = )
• Arithmetic Operators (+ , - , * , / , // , % , **)
• Relational Operators ( > , < , >= , <= , == , !=)
• Logical Operators (and, or, not)
• Membership Operators ( in , not in)
• Identity Operators (is , not is)
• Unary and Binary Operators (that work on one / two values respectively)
• Bitwise and Shift Operators (& , ^ , | , >> , << )
• Miscellaneous Operators (others that are not covered in these categories)
• These are the special symbols that help in separating one part / one
element of Python program from another.
• They help us in organizing our code well and makes it easier to
understand.
• Example of Punctuators / Separators are:
• ‘
• “ Usage
• () ab = 10 (without comma it’s one variable)
• []
a , b = 5 , 10 (with comma separator now they are two different variables.)
• {}
• ,
• :
• .
• etc
• It consist of the basic structure of the Python
Program.
• It consist of 5 main elements in it. These
are :
•Expressions
•Statements
•Comments
•Functions
• In simple words they are the formulas of Mathematics that we write
in our Python Program and it evaluates to produce a result.
• They are the combination of Operators and Operands where,
• Operators are the special symbols that helps us in
performing
calculation on the data.
• Operands are the values / literals / variables / data on which
• the
Example : a = 20 Operands / Data
calculations are being performed.
b = 34
Expression / c = a + b * 16
Formula
Operators / Symbols
• A single line of code performing a particular task
is called as statement in Python.
• These are the instructions that we write in our Python
program to give command to computer to execute it.
• Example of Statements:
• a = int ( input ( “ Enter a number “)) # Input Statement
• print(a) # Print Statement
• c = a + 22 # Expression / Calculation Statement
• These are the useful piece of text that we write
remarks for our self in order to give addition readable
information about our Python Program.
• They are ignored by the Python Interpreter.
• They can be used to give some useful information like
• Date of Creation
• Explanation of what the code is actually doing
• Name of the Team Member who had coded it
• Remembering the incomplete part that we left over when
we switched to other project.
• In Python comments are of 2 Types. These are :
• Single Line Comments : Created using # symbol at the beginning
of the line.
• Multi Line Comments : Created by enclosing the comments in ‘’’
Triple Quotation marks ‘’’
• Eg # This is a Single Line Comment
: ‘’’ This is a multi line Comment ’’’
• Eg Line Comments can be of two types:
• Single
: line Comments
• Full # this is a full line comment
• Inline Comments a = 20 # this is a variable
• Multi – Line Comments are also called as Docstring which
are used for documentation purposes of the program
developed.
• Group of Code combined together with a name in order to perform a
particular task from it is called as a Function.
• Itis created to perform Code Reusability which means create
once and used many times.
• In Python Functions are of 2 types :
• Built – In Functions
• User Defined Functions
• User Defined Functions are created using def Keyword and when we
want to use them we have to call them.
• Eg : def sum(a , b):
c=a+b
print(“the sum is “, c)
sum(23,67)
• Block is a group of statements which is formed when we use colon (:)
symbol in our Python Program.
• Block is also called as Code – Block or Suite in Python.
• Indentation is a gap of almost 4 spaces that is automatically created
when we use colon symbol to create a block of code in Python.
• The main purpose of Indentation is to tell Python Program that from
where our statements are starting and till where they will be
continued.
• When we want to end a block of code we press backspace key and
come to the unindented region of the Python Program. At this point
the block will terminate.
a = 45
b=56
if a > b : Indentation
print(“ First Number is greater “)
print(“ This is the if block of code”) Block of Code
print(“ We are ending the block here “)
else :
print(“ Second Number is greater “)
print(“This is else block “)
print(“ this statement is outside the block
”)
Note : You cannot unnecessarily indent a
Statement Termination :
• Python does not use any symbol to terminate a statement.
When you press Enter key the statement is considered
terminated by default.
• Note : We can use Semi Colon ( ; ) Symbol to separate
statements in Python
Maximum Line Length :
• It is advised to have not more than 79 characters in a line of
code.
Lines and Indentation :
• Block of code are denoted by line Indentation which is equal
Blank Lines :
• Whenever you are creating a function after another function leave a
blank line between them to increase readability of code.
Avoid multiple statements on one line :
• As we know that we can have more than one statements in one line
by separating hem with ; symbol but it is not recommended to do so.
Whitespace :
• You should always have whitespace around operators again for the
sake of increasing the readability of code.
Case Sensitive
Docstring Convention :
• Conventionaly ‘’’
Difference between Multi – Line String and Multi – Line Comments:
• Even when both of them are created using ‘’’ Triple Quotes ‘’’ how
Python is able to judge that which of them is Multi – Line String and
which is Multi – Line Comment.
• The answer to this question is:
• If you enclose any string in ‘’’ Triple Quotes ‘’’ then it will be treated
as multiline comment.
• Example: Ram is Playing
‘’’ He is a good boy ‘’’
• If you enclose any string in ‘’’ Triple Quotes ‘’’ but assign it to a
variable or use it in a print () function then Python treats it as
multiline string.
• Example: a = ‘’’ My name is Vivek ‘’’
Note : Answer the following questions in comments section of video
1. What is the gap called as which is automatically created when
we form a block of code in Python?
2. Which punctuator is used to form a Block of Code in python?
3. What is the other name for multiline comments?
4. The mathematical formulas are called as _ in
Python.
5. What is the name of the = operator in Python?