Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
6 views

(ii) FundamentalsBasics of Python (Math module included)

The document provides a comprehensive overview of Python programming, covering essential topics such as Python's character set, tokens (keywords, identifiers, literals, punctuators, operators), data types, and variable concepts. It explains mutable and immutable data types, the structure of lists, tuples, and dictionaries, as well as how to accept input and produce output in Python. Additionally, it discusses the significance of variables, their assignment, and internal workings in Python.

Uploaded by

jainavish45
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

(ii) FundamentalsBasics of Python (Math module included)

The document provides a comprehensive overview of Python programming, covering essential topics such as Python's character set, tokens (keywords, identifiers, literals, punctuators, operators), data types, and variable concepts. It explains mutable and immutable data types, the structure of lists, tuples, and dictionaries, as well as how to accept input and produce output in Python. Additionally, it discusses the significance of variables, their assignment, and internal workings in Python.

Uploaded by

jainavish45
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 73

Let’s Learn

Together…..

Know Python Bytes


www. knowpythonbytes. blogspot. com
Mrs. Payal
Bhattacharjee, PGT( C.
CONTENTS
( Learning
FEATURES OF PYTHON: Outcomes ) 
 Python Character Set
 Tokens(Keywords, Identifiers, Literals, Punctuators, Operators)
 Knowledge of Data Types and Operators
 Accepting input from the console
 Assignment statement
 Mutable/Immutable data types
 Introduction to Variable,
 Variable Internals and methods to manipulate it,
 Concept of L-value and R-value of a variable
 Operators and Types and their precedence:
Binary and Unary Operators, Arithmetic Operators,
Augmented Assignment Operators, Relational Operators,
Logical Operators,
 Expressions
PYTHON CHARACTER SET
A set of valid characters recognized by python.
Python uses the traditional ASCII character set. The
latest version recognizes the Unicode character set.
The ASCII character set is a subset of the Unicode
character set.
• Letters :- A-Z , a-z
• Digits:- 0-9
• Special symbols :- Special symbol
available over
keyboard
• White spaces:- blank space, tab,
carriage return, new line,
TOKENS
Smallest individual unit in a program is called a token.
They are:
 K eywords
 I denti fi ers
 L i terals
 P unctuators
 O perators
My funda of remembering Tokens: KILPO it’s just a shortcut given by me for remembrance ;)
TOKEN KEYWORDS
Keywords are the words that convey a special meaning to the
language compiler/interpreter. They are reserved for special
purpose and must not be used as normal identifier names.
and exec not
as finally or
assert for pass
break from print
class global raise
continue if return
def import try
del in while
elif is with
else lambda yield
except
TOKEN IDENTIFIERS
Identifiers are the fundamental building blocks of a program which
are used to identify a variable, function name, class name, module
name or any object.
RULES OF WRITING AN IDENTIFIER
 An identifier starts with a letter A to Z, a to z or an underscore ( _ ) followed by
zero or more letters, underscores and digits (0 to 9).
 Identifier name canNOT start with a digit.
 Python does NOT allow special characters other than underscore ( _ ).
 Identifier must NOT be a keyword of Python.
 Python is a case sensitive programming language that is uppercase letters
(capital letters) and lowercase letters (small letters) are treated differently.
Eg. Marks and marks are two different identifiers in Python.
• Some valid identifiers : Mymarks , , tv9r , Avg_2 , _no
file12
XI-CS , E mail ,
• Some invalid identifier : 4Qtr , global %age
, Starts with digit keyword
Special characters - (hyphen) space %
TOKEN LITERALS / values
Literals are data items that have a fixed value.
Python allows several kind of literals:
Numeric
Literals
• Int (signed integers)  Positive or Negative
whole numbers with no decimal point Eg.
10, -96, 1234, 0
• Floating point/Real values  float represent
real numbers and are written with a decimal
point dividing the integer and fractional part.
Eg 2.0,54.7,-12.0,-0.075, .4
• Complex (complex numbers)  a+bj , where
a and b are floats and J(or j) represents √-1 ,
which is an imaginary number. a is the real
part and b is the imaginary part of the
TOKEN LITERALS contd..

Boolean Literals
True and False are the only two Boolean
values

Special Literal None


None literal represents absence of a
value.
That is why nothing is printed
for the value of b.
String Literal
String literal is a sequence of characters
surrounded by quotes (single or double or
triple)
String literals can be written in either single
TOKEN LITERALS contd..
ESCAPE SEQUENCES / Non-graphic characters
TOKEN LITERALS contd..
ESCAPE SEQUENCE Examples

The cursor moves to the


next line after printing
‘Hello’

The cursor keeps one


tab space after
printing ‘wonderful’

The string when


written inside ‘ ‘
single quote gives
an error when we
try to print one ‘
(apostrophe
symbol).
So, to remove the
error we use \
escape sequence.
The same thing
TOKEN PUNCTUATORS
Punctuators are certain symbols which are used in
the programming languages to organize
programming sentence and structures, and indicate
the rhythm and emphasis of expressions, statements,
and program structure.

Most common punctuators of Python programming


language are:

‘ “ # \ ( ) [] {} @ , : . `
=
TOKEN OPERATORS
Operators are tokens that trigger some computation/ action
when applied to variables and other objects in an
expression.
UNARY Unary - , ~ Bitwise complement , not logical
Unary + , OPERATORS
negation
BINARY OPERATORS
ARITHMETIC OPERATORS: +,-,*,/,%,//,**
AUGMENTED ASSIGNMENT OPERATORS: = , +=,-=,*=,/=,%=,//=,**=
RELATIONAL OPERATORS: >,<,>=,<=,==,!=
LOGICAL OPERATORS: and , or, not
MEMBERSHIP OPERATORS: in, not in
IDENTITY OPERATORS: is, is not
BITWISE OPERATORS: &(Bitwise AND), ^(Bitwise XOR), |(Bitwise OR)
SHIFT OPERATORS: << (Shift Left) , >> (Shift Right)
DATA
The kind of data for handling the data used in a
TYPES
program code is the data type.

CORE DATA TYPES

NUMBERS NONE SEQUENCES MAPPINGS

Floating Dictionary Sets


Integer Complex
Point

Boolean
Strings Tuple List
MUTABLE AND IMMUTABLE TYPES
• Mutable types:
The mutable types are those whose values can be
changed in place.
Only three types are mutable in Python.
These are: Lists, dictionaries
and sets.

• Immutable types:
The immutable types are those that can never
change their value in place.
In python , the following are the
DATA TYPE: Number in Python
It is used to store numeric values.

Python has three numeric types:

1. Integers
2. Floating point numbers
3. Complex numbers.
DATA TYPE: NUMBER  Integer
Integer or int are
positive or negative numbers
with no decimal
point.
Integers in Python are of
unlimited size.
Type Conversion to Integer , int( ) function

int() function converts


any data type to
integer.
DATA TYPE: NUMBER  Float
Float are positive or
negative real numbers with
decimal point. Some Floating
point number examples:
4.5, 2.0, -38.9,-18.0

Type Conversion to Float ,


float( ) function
float() function converts any
data type to floating point
numbers.
DATA TYPE: Complex Number
• Complex numbers are combination of a real and imaginary part.
• Complex numbers are in the form of X+Yj
, where X is a real part and Y is imaginary part. We know, in
mathematics, j stands for √-1
• Using complex() function , we can also create complex
numbers.
DATA TYPE: Boolean
• Boolean takes any two values, either True or False
• Every integer number, float number or complex number whether
negative or positive takes a Boolean value True.
• Value 0 , 0.0 , 0+0j are considered False in Boolean.
DATA TYPE: STRING
STRINGS in Python
in Python
A string is a sequence of characters. In python, we can create string
using single('') or double quotes(""). Both are same in python.
FORWARD INDEX DIRECTION
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
C omp u t e r
15 S c i e n c e
-16 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1
BACKWARD INDEX DIRECTION

NOTE:-
The index (also called subscript) is the numbered position of a letter
in the string. In python, indices begin from
0,1,2,…. upto (length-1) in the forward direction and
-1,-2,-3,….. (-length) in the backward direction.
where length is the length of the string.
DATA TYPE: working with STRING examples
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18

C omp u t e r S c i e n c e ! ! !
-19 -18 -17 -16 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1
DATA TYPE: String contd..
Python allows to have two string types:
1) Single line strings (Basic strings)
Text enclosed in single quote ‘India’ or in double quotes “Bharat”
are normally single line strings i.e. they must terminate in one line.

2) Multiline strings
Text spread across multiple lines as one single string.
Two ways of treating multiline strings:-
(i) By adding a backslash at the (ii) By typing the text in triple quotation or
end of normal single apostrophe mark (No backslash
quote/double quote strings. needed at the end of line)
DATA TYPE: LIST in Python
A list in Python represents a list of comma-separated values of any data type
between square brackets e.g. following are some lists:
LIST is mutable- one can change/add/delete a list’s element)
FORWARD INDEX DIRECTION
0 1 2 3 4 5
10 20 30 40 50 60
-6 -5 -4 -3 -2 -1
BACKWARD INDEX DIRECTION
DATA TYPE: TUPLE in Python
Tuples are represented as list of comma-separated values of any data
type within parentheses. Some examples of tuples:
Tuple is immutable - one cannot change the values of a tuple.
FORWARD INDEX DIRECTION
0 1 2 3 4 5
10 20 30 40 50 60
-6 -5 -4 -3 -2 -1
BACKWARD INDEX DIRECTION
DATA TYPE: DICTIONARY in Python
Dictionary data type is an unordered set of comma-separated key: value
pairs, within { } , with the requirement that within a dictionary, no two keys can be
the same (i.e. there are unique keys within a dictionary). Some examples of Dictionary:
Value
D = { 10 : ' CS' , ' IP': 50 }
Key
CONCEPT OF VARIABLES
• Variable is a name (Named Labels)
given to a memory location that refers
to a value and whose values can be
used and processed during program
run.
NOTE:
• Python variables are created by
Here, marks, Name and
assigning value of desired data type to Item_price are the named labels
them. The assignment operator = is used (variables) with datatype inferred
to assign the values from RHS to LHS as Integer, String and Float for the
variable. Eg. Assign integer value to values 100, ‘Agni’, 999.90
create integer variable, string value to a respectively.
variable to create string variable.
• Python is a type infer language that marks
means you don't need to specify the Name
datatype of variable. Python 100
automatically get variable datatype
depending upon the value assigned to ‘Agni’
the variable. 999.90
MEMORY LOCATIONS: Imagine a Table top with different boxes having some
values stored in them. The variables which you will create are the tags (Like
price tags on items in a mall) , which you will place on the top of the boxes.
These tags(variables) will represent (or point)
those boxes with the value assigned to the
variables. Unlike other programming languages,
VARIABLES ARE NOT SORAGE CONTAINERS
in PYTHON

B
1 2 3 4 1 2 3 4
B
10 20 30 40 10 20 30 40
A
15 25 35 45 15 25 35 45
A
100 200 300 400 100 200 300 400

11 22 33 44 11 22 33 44
ASSIGNING VALUES TO VARIABLES
• A Variable is not created ASSIGNING SAME VALUE TO MULTIPLE
VARIABLES
until some value is assigned
to it.

ASSIGNING DIFFERENT VALUES TO


MULTIPLE VARIABLES

SWAPPING VARIABLES’
ASSIGNING VALUES TO VARIABLES ASSIGNING None VALUES
THROUGH AN EXPRESSION. VALUE (nothing) TO
A VARIABLE
L-VALUE and R-VALUE OF A VARIABLE
Lvalue: Expressions which Rvalue: Expressions which
can be given on the LHS(Left can come on the RHS(Right
Hand Side) of an assignment. hand side) of an assignment.
NOTE: In Python, assigning a value
to a variable means, variable’s
label is referring to that value
VARIABLE INTERNALS
VARIABLE
DATA
VALUE ID
TYPE
id of an object (Identity)
The id of an object is generally the memory location of the object. Although id is
implementation dependent but in most implementations it returns the memory
location of the object. id() is a built-in function that returns the id of an object.
Consider, the following code

marks mark
100
100
s int 1852878304
More on VARIABLE INTERNALS with example

Here,

a b c
 a, b, c are named labels/
variable names /object names

10 20
 10 and 20 are the values
 int is the data type or
<class type> of the
int int
variables /objects
 1805363264 and 1805363424
1805363264 1805363424
are the id of the objects
INPUT through input() function and
OUTPUT through print() statement
 To take input from the user, input() function is used. input() function
takes values in string data type.
Syntax of input Function
input()
 To print/display the contents on the console(monitor screen),
print() function is used.
Syntax of print Function
print(expression/
variable)

NOTE:
Interactive
mode
supports displaying of data ,
both with print() function
and also directly writing
NOTE: But, to display in Script mode , print() function is required to
display the data (contents), otherwise nothing is printed
More on INPUT through input() function and
OUTPUT through print() statement…….
# input () takes
string value by
default.

# But price
should be of
numeric value

#We can use


int() or float ()
function with
the input
function
Some more on input() and print()

sep and end parameters of print()


function.
sep is the separator parameter which separates the strings given in print function.
The default separator (in the absence of sep) is a space ‘ ’.
end parameter denotes the end character to be given at the last of the
print() functions
data/content.
DYNAMIC TYPING
A Variable pointing to a value NOTE:
Here, variable
of a certain type, can be made a changes its
to point to a value/object of data type from
‘int’ to ‘string’
different type. dynamically
This is called Dynamic typing. ( i.e. during run
time).

DYNAMIC TYPING error


UNARY OPERATORS
Unary + , Unary ~ Bitwise complement , not logical
-, negation
BINARY OPERATORS
ARITHMETIC OPERATORS: +,-,*,/,%,//,**
AUGMENTED ASSIGNMENT OPERATORS: = , +=,-=,*=,/=,%=,//=,**=
RELATIONAL OPERATORS: >,<,>=,<=,==,!=
LOGICAL OPERATORS: and , or, not
MEMBERSHIP OPERATORS: in, not in
IDENTITY OPERATORS: is, is
not
BITWISE OPERATORS: &(Bitwise AND), ^(Bitwise XOR), |(Bitwise
ARITHMETIC OPERATORS
1) BINARY OPERATOR: requires two A + B , where A and B
values(or operands) to calculate a final are Operands and + is the
answer
SYMB BINARY DESCRIPTION Operator
OL OPERATOR

+ ADDITION
Operator
returns sum of two values

- SUBTRACTION
Operator
subtracts second operand from first operand

* MULTIPLICATION
Operator
multiplies two values

/ DIVISION
Operator
divides first operand by the second operand and
always return a float value

% MODULO
Operator
produces the remainder of dividing the first
operand by the second operand

// FLOOR DIVISION
Operator
divides the first operand with the second operand
in which the whole part of the result is given in the
output , the fractional part is truncated

** EXPONENTIATION
Operator
returns the no. raised to a power(exponent)
Negative Number Arithmetic

NOTE:
In Mathematics,
XY = X**Y in Computer
Science.

X-Y = 1/(X**Y)
ARITHMETIC OPERATORS
2) UNARY OPERATOR : -A , where A is the
single
operators that act on one operand) Operand and - is the Unary
Operator
Unary +
 If a=5 then +a means 5
 If a=0 then +a means 0
 If a=-4 then +a means -4

Unary –
 If a=5 then –a means -5
 If a=0 then –a means 0
 If a=-4 then –a means 4

NOT is a Unary operator which has been


covered under Logical operators
Au gmented assi gnm ent operator
OPERATORS DESCRIPTION EXAMPLE EQUIVALENT
ASSIGNMENT

= Assigns values from right side


operands to left side operand.
a=b a=b

+= Add 2 numbers and assigns the


result to left operand.
a=a+b a+=b

/= Divides 2 numbers and assigns


the result to left operand.
a=a/b a/=b

*= Multiply 2 numbers and assigns


the result to left operand.
a=a*b a*=b

-= Subtracts 2 numbers and assigns


the result to left operand
a=a-b a-=b Here,
a*=b
%= Modulus 2 numbers and assigns
the result to left operand.
a=a%b a%=b
a=a*b
is equivalent to

b-=c
//= Floor division on 2 numbers and
assigns the result to left operand
a=a//b a//=b is equivalent to
b=b-c
**= Calculate power on operators and
assigns the result to left operand
a=a**b a**=b c/=5
is equivalent to c=c/5
RELATIONAL OPERATORS
 Relational Operators are used to compare the values of Left Hand
Side (LHS) and Right Hand Side (RHS) of the relational operator.
 Relational Operators always return Boolean value True or False
OPERATOR DESCRIPTION EXAMPLE
== Equal to,
return True if LHS is equal to RHS of the operator
A==B
!= Not Equal to,
Returns True if LHS is not Equal to RHS
A!=B
> Greater than,
Returns True if LHS is greater than RHS
A>B
>= Greater than or Equal to,
Returns True if LHS is greater than or equal to RHS
A>=B
< Less than,
Returns True if LHS is less than RHS
A<B
<= Less than or Equal to,
Returns True if LHS is less than or equal to RHS
A<=B

Here, A and B can be an expression or a variable.


Some examples of Relational Operator

NOTE: T of True and F of False is always in capital letters


MORE on RELATIONAL OPERATOR principles
FOR NUMERIC DATA TYPES FOR LISTS AND TUPLES
values are compared after Two lists and similarly two tuples
removing trailing zeros after are equal if they have same elements in
decimal point from a floating the same order.
point number.

Some more principles


on using parentheses ()
X+Y<Y*2 is equivalent to
(X+Y)<(Y*2)

FOR STRING DATA TYPES  In ASCII value,


A=65,B=66,C=67.....Z=90
a=97,b=98,c=99…… z=122
‘ ’ = 32
(blank or white space)

FOR BOOLEAN
True is equivalent
to 1 and Boolean
False is equivalent
to 0
IDENTIT Y OPERATOR ( is , not)
is
Is, is not are the operators which compares two objects in terms
their memory locations which is their corresponding ide of ntity
(id)
OPERATORS DESCRIPTION EXAMPLE
is It returns True, if two variables point to the
same object, else it returns false
P is Q

is not It returns True, if two variables point to different


objects, else it returns false P P isQnot Q
int 10
1805363264

R
int 20
Here, P and Q can be an expression or a variable object. 1805363424
EQUALITY OPERATOR (==) and
IDENTITY OPERATOR (is)
a b
char ‘Hi’
58401024

c
char ‘Hi’
64317056
NOTE: c is the input taken from User.
The reason behind this behaviour is that there are few cases where
Python creates two different objects that both store the same value.
These are:
i) Input of strings from the console
ii) Writing integer literals with many digits (very big integers)
iii) Writing floating point and complex literals
MEMBERSHIP OPERATOR
Membership operator tests for Membership in a sequence.
Returns Boolean True or False
OPERATOR DESCRIPTION
in Results to True value if it finds a variable at the LHS of in operator in the
sequence mentioned in the RHS of the in operator, else it returns False

not in Results to True value if it does not find a variable at the LHS of in operator in
the sequence mentioned in the RHS of the in operator, else it returns False

Program
written in
script
mode

Output
visible on
Interpreter
shell
LOGICAL
OPERATORS
or , and ,
Logical operators are used to
not
perform logical operations on the
given two variables or values.
or operator
The or operator combines two expressions, which make its operands.
i) Relational expression as operands X Y
X
Tea or Y
Coffee X Y X or Y
False False False
False True True
NOTE: If either Tea or Coffee is True False True
available at home, you can have X Y
it, hence True. If nothing available True True True
out of the two then, False

ii) Numbers / Strings / Lists as operands


In an expression X or Y , if first operand (i.e. expression X) has false, then return
second operand Y as result, otherwise return X.
NOTE: Every integer
X Y X or Y number, float number or
False False Y complex number whether
negative or positive takes
a Boolean value True.
False True Y Value 0 , 0.0 , 0+0j are
True False X considered False in
Boolean.
True True X
and operator
The and operator combines two expressions, which make its operands.
i) Relational expression as operands X Y
X
Pen and Paper
Y
X Y X and
Y
False False False
NOTE: To write something using pen
and paper, you need both pen and False True False
paper. Then only its True and you will X Y
be able to write. Otherwise, in absence True False False
of anyone out of the two will be False
True True True
ii) Numbers / strings / Lists as operands
In an expression X and Y , if first operand (i.e. expression X) has false, then return first
operand X as result, otherwise return Y.
X Y X and Y NOTE: Every integer
number, float number or
False False X complex number whether
False True X negative or positive takes
a Boolean value True.
True False Y Value 0 , 0.0 , 0+0j are
considered False in
True True Y Boolean.
not
 The logical not operator works on single
operator
expression or operand i.e. it is a unary operator.
X Not(X)
 Not operator negates or reverses the truth =Y
value of the expression. True False
 A non-zero value is always true(1)
(1) (0)
i.e. 5 , 24,-38 all are true value.
 A zero (0, 0.0, 0+0j) is a false(0) value False True
 Empty string ‘’ is considered as False. (0) (1)
 A white space ‘ ’ is considered as True. X

Y
CHAINED COMPARISON OPERATOR

Both the
statements
are
equivalent.
Hence, the
output is
same.
OPERATOR PRECEDENCE
Operator Description
** Exponentiation (raised to the power) Highest
~+- Complement unary plus and minus(method Priority
names for last two are +@ and -@)
*/%// Multiply, divide, modulo and floor division
+- Addition and Subtraction
>> << Right and left bitwise shift
& Bitwise ‘AND‘
^| Bitwise exclusive ‘OR' and regular ‘OR'
<= <> >= Comparison operators
< > == != Equality operators
= %= /= //= += ‘= “= Assignment operators
is , is not Identity operators
in , not in Membership operators
Lowest
not , or , and Logical operators Priority
OPERATOR ASSOCIATIVITY
 Left-to-right associativity for all the operators except
exponentiation ** operator
 For eg. multiplication(*),division (/) and floor division
operator(//) have the same precedence,
In same expression the operator on the left is evaluated first
and then the operator on its right and so on.
Here,
* /
Left to Right Associativity // have
the
same
Same precedence
as level. So, by
default left
to
right
associativity
while
Some more examples on
OPERATOR ASSOCIATIVITY
Not the
same
Same
NOTE:
as
Here, in the expression / (Division operator )
has the higher priority the + (Addition
operator) in the precedence table.

Not the
same
Same
as EXCEPTIONAL CASE:
If an expression contains **, then
this exponentiation operator has right
to left associativity while execution.
Expression= Atom + Operators
• An atom is something that has a value. Identifiers, literals,
strings, lists, tuples, sets, dictionaries etc.
• An atom is something that has some value.
EXPRESSION: It is referred as a valid combination of
operators and atoms. An expression is composed of one or more
operations.
Types of Expressions
(i) Arithmetic expressions
(ii) Relational expressions
(iii) Logical expressions
(iv) String expressions

Two string operators + and *


DATA TYPE
CONVERSIONS
The process of converting the value of one data
type (integer, string, float, etc.) to another
data type is called type conversion.

Python has two kinds of type conversion.


i) Implicit Type Conversion
ii) Explicit Type Conversion
IMPLICIT TYPE CONVERSION
In implicit type conversion, Python
automatically converts one data type
to another data type. This process doesn’t
need any user involvement.
Eg.
EXPLICIT TYPE CONVERSION
In Explicit Type Conversion, user converts
the data type of an object to required
data type. We use the predefined functions
like int(),float(),str() etc.
Eg.

Changing Data type of s from <str> type to <int> type


DATA HANDLING  WORKING WITH
MATH MODULE
Some mathematical functions in math module are:
Write this statement before using the
following functions in the math module.

FUNCTION Prototype Description


(General form)

sqrt math.sqrt(num) The sqrt() function returns


the square root of num.If
num <0, domain error
√25 = 5
occurs
24=16
pow math.pow The pow() function returns
this raised to exp power
(base, exp)
i.e., base exp. A domain 2-4 = 1
error occurs if base=0 and 16
exp<=0; also if base <0 and =0.0625
exp is not integer.

fabs math.fabs(num) The fabs() functions returns


the absolute value of num |18|=18.0
i.e. the magnitude of the |-18|=18.0
number without sign(+ or -)
FUNCTION Prototype Description Q) Find :
(General form)
math.ceil(2.7) and
math.floor(2.7)
floor math.floor(num) The floor()
functions
returns the
largest integer
value not
ceiling
greater than 2.7
num
floor
ceil math.ceil(num) The ceil()
functions
returns the
smallest
integer not less
than num.

HINT:
Imagine a room between the two integer points on
the y axis where the given value will lie.
ceiling
Now, the integer value which comes in the ceiling of
- 2.7
the room is the answer for ceil function . Similarly floor
integer value which comes in the floor of the room is
the answer for floor function.
FUNCTIO Prototype Description
N (General
form)

exp math.exp(arg) The exp() function


returns the natural
logarithm e raised to
the arg power
Value of e is 2.718

sin math.sin(arg) The sin() functions


returns the sine of
arg.the value of arg must
be in radians.

Cos math.cos(arg) The cos() functions


returns the cosine of
arg. The value of arg
must be in radians

tan math.tan(arg) The tan() function


returns the tangent of
arg. The value of arg
must be in radians.
FUNCTION Prototype Description
(General form)

log math.log
(num,[base])
The log() function
returns the natural
logarithm for num. A
domain error occurs if
num is negative and a
range error occurs if the
argument num is zero.

log10 math.log10(num) The log10() function


returns the base 10
logarithm for num. A
domain error occurs if
num is negative and
range error occurs if the
argument is zero.

degrees math.degrees(x) The degrees()


converts angle x from
radians to degree

radians math.radians(x) The radians()


converts angle x from
degrees to radians
APPLICATION OF MATH MODULE FUNCTIONS IN
MATHEMATICAL EXPRESSIONS
Q) Write the corresponding Python Expressions from the
mathematical expressions:
i) ut+1/2 ft2
Ans. u*t+1/2*f*t*t
Alternative way

u*t+(1/2)*f*math.pow(t,2)

ii) |e2y-x|
Ans.
math.fabs(math.exp(2*y)-x)
TIME TO SOLVE…………… 
Q1) Give the output for the Q2) Write the corresponding
Python Expressions from the
print statements mathematical expressions:
import math
i) |a|+b >= |b|+a
a=math.pow(2,5)
print(a) ii)

print(math.sqrt(81))
print(math.ceil(12.8)) (iii) Cos(x)

print(math.floor(12.8) - 5x

print(math.ceil(-38.5)) iv) Tan(x)

print(math.floor(-38.5))
Bibliograhy and References
• Google
• Wikipedia
• Quora
• geektogeeks
• Book: XI Computer Science
– By Sumita Arora, Dhanpat Rai Publication
2020 Edition
• Book: XI Informatics Practices
– By Sumita Arora, Dhanpat Rai Publication
2020 Edition
Swami Vivekananda

Stay safe. Stay aware. Stay

You might also like