Chapter 3 Python Fundamentals Part 2 1
Chapter 3 Python Fundamentals Part 2 1
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.
• 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.