Python Module-1 Notes (21EC646)
Python Module-1 Notes (21EC646)
Python Basics
Syllabus:
Python Basics:
• Python Language Features,
• History ,
• Entering Expressions into the Interactive Shell,
• The Integer, Floating-Point, and String Data Types,
• String Concatenation and Replication,
• Storing Values in Variables,
• Your First Program,
• Dissecting Your Program,
• Flow control,
• Boolean Values,
• Comparison Operators,
• Boolean Operators,
• Mixing Boolean and Comparison Operators,
• Elements of Flow Control,
• Program Execution,
• Flow Control Statements,
• Importing Modules,
• Ending a Program Early with sys.exit(),
• Functions
• def Statements with Parameters,
• Return Values and return Statements,
• The None Value,
• Keyword Arguments and print(),
• Local and Global Scope,
• The global Statement,
• Exception Handling,
• A Short Program: Guess the Number
PYTHON APPLICATION PROGRAMMING
Features of python:
1. Python is free and open-source programming. The software can be downloaded and used
freely.
2. It high level programming language.
3. Easy Syntax: Python uses easy-to-read syntax and easy to learn.
4. It is portable. That means python programs can be executed on various platforms without
altering them.
5. Indentation: Python uses indentation to define code blocks, like loops and functions,
instead of curly braces or keywords like "end". This enforces clean and readable code.
6. Interpreted: Python is an interpreted language, meaning that code is executed line by line.
The Python programs do not require compilation. Python converts the source code into an
intermediate form called bytecodes and then translates this into the native language of your
computer and then runs it.
7. It is an object oriented programming language
8. It can be embedded within your C or C++ programs.
9. It has very rich set libraries and library functions
10. It has very powerful built in data types.
11. Dynamic Typing: You don't need to declare the type of a variable explicitly. Python
automatically determines the data type during execution.
12. Dynamic Memory Management: Python automatically handles memory allocation and
deallocation. You don't need to worry about memory management like in languages such
as C or C++.
13. Cross-Platform: Python is available on multiple platforms, including Windows, macOS,
and Linux, making it easy to write code that works across different operating systems
# A floating point
height = 5.8
# A string
name = "Sachin Tendulkar"
x$=4 #contains $
SyntaxError: invalid syntax
if=10 # if is a keyword
SyntaxError: invalid syntax
Example :
# An integer assignment
x= 45
Data Types
• A data type indicates the type of data (value), such as integer, string, float, etc.
• The most common data types in Python are integers, floating-point numbers, and strings.
• To find the type of the value, we have to use the inbuilt function type()
Integers
Definition: Whole numbers without a decimal point.
Examples: -2, -1, 0, 1, 2, 3, 4, 5
Floating-Point Numbers
Definition: Numbers with a decimal point.
Examples: -1.25, -1.0, -0.5, 0.0, 0.5, 1.0, 1.25
Note: The number 42.0 is a floating-point number, not an integer.
Strings
Identifiers:
• An identifier is a name given to a variable, function, class or module.
• Identifiers may be one or more characters in the following format:
x = 5
y= 10
z= x + y
print(z)
Output: 15
Keywords [Words]
• Every programming language has its own constructs to form syntax of the language.
• Basic constructs of a programming language include set of characters and keywords
• Keywords are reserved words. Each keyword has a specific meaning and they are meant to
perform specific task.
.
An expression
>>> y= x + 25
>>>print(y)
o Arithmetic Operators
o Assignment Operators
o Comparison Operators
o Logical Operators
o Bitwise Operators
Arithmetic Operators
Operator Description Example
+ Addition y=a +b
- Subtraction y=a -b
* Multiplication y= a * b
/ Division (always results into float) y= a/ b
y=a % b
% Modulus (Remainder of the division)
(Remainder of a/b)
Floor division (returns whole number)
The division of operands where the output
// is the quotient in which the digits after the y=a // b
decimal point are removed.
Bitwise operators
Operator Description Example
& Bitwise AND x&y
| Bitwise OR x|y
~ Bitwise NOT ~x
^ Bitwise XOR x^y
>> Bitwise right shift x>>
<< Bitwise left shift x<<
Modulus operator
• The modulus operator works on integers and yields the remainder of the division
• In Python, percent sign (%) represents the modulus operator.
The syntax:
a=7
b=3
y= a%b => output =1
Here 7 divided by 3, so quotient is 2 and remainder is 1.
• The modulus operator is very useful.
o For example, we can check whether one number is divisible by another:
if x % y =0, then x is divisible by y.
o Modulus operator can be used to extract the right-most digit or digits from a number.
For example: 197 % 10 = 7 => here from 197 the right most digit 7 is extracted
1083%100= 83 => here from 1083 the 2 right most digits 83 are extracted
o The modulus can be used to find the even and odd numbers etc
• In python the value of the modulus is calculated using this expression.
y=a%b
= a- (a//b) * b
[Note: here a//b is floor division]
Example : -11% 9
= -11- (-11//9) * 9
=-11-(-1.22) *9
=-11-(-2) *9
=-11-(-18)
=7
Example : -5% 4
= -5- (-5//4) * 4
= -5 -(-1.25) * 4
=-11-(-2) *4
=-11-(-8)
=3
• Parentheses: have the highest precedence in any expression. The operations within
parenthesis will be evaluated first.
Examples: 2 * (3-1) => Output= 4
(1+1)**(5-2) => Output= 8
The addition has to be done first and then the sum is multiplied with c
• Exponentiation: it has the 2nd precedence. But it is right associative. That is, if there are
two exponentiation operations continuously, it will be evaluated from right to left (unlike
most of other operators which are evaluated from left to right).
Examples: 2**1+1 => Output= 3
• Multiplication and division: Multiplication and Division are the next priority. Both
same precedence. Operators with the same precedence are evaluated from left-to-right.
Examples: 2*3-1 => Output= 5
5-2*2 => Output= 1
5*2/4 => Output= 2.5
• Addition and Subtraction are the least priority. Both same precedence. Operators with
the same precedence are evaluated from left-to-right.
Examples: 5-3-1 => Output= 1
5-2+2 => Output= 5
6-(3+2) => Output= 1
String Concatenation
+ Operator: Joins two strings together.
>>> first = 10
>>> second = 15
>>> print(first+second) #Here + operator performs the addition
Output = 25
Example: 'Alice' + 42
Example:
'Alice' + str(42)
Output : 'Alice42'.
String Replication
* Operator: Repeats a string a specified number of times.
Example: 'Alice' * 5
Output: 'AliceAliceAliceAliceAlice'.
Comments
• Comments are used to improve the readability of the program.
• Comments are not executed by the interpreter
• It is a good programming practice to add comments to the program wherever required.
• This will help someone to understand the logic of the program.
• Comments are used primarily to document the meaning and purpose of source code
• For large and complex software, programmers work in teams and sometimes, a program
written by one programmer may be used or maintained by another programmer. In such
situations, documentations (comments) help to understand the working of the program.
• Comment may be in a single line or spread into multiple lines.
• A single-line comment in Python starts with the symbol #.
• Multiline comments are enclosed within a pair of 3-single quotes.
• Example1:
or
myName = input('What is your name?') # in single statement
>>> str(-3.14)
'-3.14'
int() Examples:
>>> int('42')
42
>>> int('-99')
-99
>>> int(1.25)
1
>>> int(1.99)
1
float() Examples:
>>> float('3.14')
3.14
>>> float(10)
10.0
int('99.99')
ValueError: invalid literal for int() with base 10: '99.99'
>>> int('twelve')
Traceback (most recent call last):
File "<pyshell#19>", line 1, in <module>
int('twelve')
Output
If the user enters '4':
myAge is '4'.
int(myAge) converts '4' to 4.
int(myAge) + 1 results in 5.
str(5) converts 5 back to '5'.
The final message is: "You will be 5 in a year."
Flow Control
• Programming allows instructions to be executed based on conditions.
• Programs rarely execute straight through from start to finish.
• Flow control statements decide which instructions to run under specific conditions.
Boolean values, comparison operators, and Boolean operators help determine the outcome of
flow control statements.
Boolean Values:
• Boolean values, which can be either True or False, are used in expressions and stored in
variables.
• They help in flow control by determining the outcome of conditional statements, such as if
statements,
Comparison operators
• Comparison operators return Boolean values by comparing two values.
• Essential for making decisions in flow control statements (if, while).
• Used widely beyond flow control, such as in loops and conditions.
Boolean Operators
• The three Boolean operators (and, or, and not) are used to compare Boolean values.
• Used in conditional statements (if, elif, else), loops (while, for), and other decision-
making contexts.
1. if statements
2. Alternative Execution (if else)
3. Chained Conditionals: if elif else
4. Nested Conditionals
if statements
Example 2
mark=int(input(“Enter your marks”)
if mark>=35: #colon at the end of if header
print(“Pass”) #Indentation (part of if block)
Print(“Congratulations”) #indentation (part of if block)
print(“Hello it is not part of if block”) #No indentation (Not a part of if block)
• There is no limit for, the number of statements in the if body, but there must be at least
one.
• But in some occasions, the program should not do anything when the condition is true, in
such cases, the statement block can be skipped by just using pass statement as shown
below
if x < 0 :
pass # do nothing, if number is negative
else:
diff = num2 - num1
print("The difference of",num1,"and",num2,"is",diff)
tax= 0.1*salary
print(“ Tax amount to be paid is :”, tax)
else salary>100000
tax= 0.3*salary #30% tax
print(“ Tax amount to be paid is :”, tax)
marks=float(input("Enter marks:"))
if marks >= 80:
print("First Class with Distinction")
elif marks >= 60 and marks < 80:
print("First Class")
elif marks >= 50 and marks < 60:
print("Second Class")
elif marks >= 35 and marks < 50:
print("Third Class")
Nested Conditionals
• One conditional statement can be nested within another conditional statement.
• Nesting can be done in many ways as per the requirement in the program.
• In nested conditionals, even though indentation of the statements makes the inner and
outer structure visible, but still it is difficult to read the nested conditionals very quickly
Example 1:
gender=input("Enter gender:")
age=int(input("Enter age:"))
if gender ==’M’
if age >= 21:
print("Boy, Eligible for Marriage")
else:
print("Boy, Not Eligible for Marriage")
elif gender == "F" :
if age >= 18:
print("Girl, Eligible for Marriage")
else:
print("Girl, Not Eligible for Marriage")
Example 2:
x=int(input(“ Enter the first number”)
y=int(input(“ Enter the first number”)
if x == y:
print('x and y are equal')
else:
if x < y:
print('x is less than y')
else:
print('x is greater than y')
Another method
num1=int(input(“ Enter the first number”)
num2=int(input(“ Enter the second number”)
num3=int(input(“ Enter the third number”)
max=num1
if num2>max:
max=num2
if num3 > max:
max=num3
print(“ the maximum number is”, max)
Example: Write a program to create a simple calculator performing any four basic operations.
Program has to ask the choice (mathematical operation) from user and that particular operation
has to be executed
result = 0
if op == "+":
result = val1 + val2
elif op == "-":
if val1 > val2:
result = val1 - val2
else:
result = val2 - val1
elif op == "*":
result = val1 * val2
elif op == "/":
if val2 == 0:
print("Error! Division by zero is not allowed. Program terminated")
else:
result = val1/val2
else:
print("Wrong input, program terminated")
print("The result is ",result)
ITERATION
• Iteration is a process of repeating some tasks. In programming, iteration is often referred to
as 'looping'
• In programming, many times, we require a set of statements to be repeated certain number
of times and/or till a condition is met.
• Every programming language provides certain constructs to achieve the repetition of tasks.
• Python offers two kinds of loop:
o while loop. (Indefinite loop)
o for loop (definite loop)
• while loop is used to repeat block of code till condition is true/met. This is condition-
controlled loop.
• The while loop iterates till the condition is met and hence, the number of iterations are
usually unknown prior to the loop. Hence, it is sometimes called as indefinite loop
Example 2: Write program to Print first 5 natural numbers using while loop
count = 1
while count <= 5:
print(count)
count = count +1
Output:
1
2
3
4
5
Example 2: Write program to Print even numbers from 0 to 10 using while loop.
i=0
while i <= 10:
print(i)
i = i +2
Example 4: Write program to print Odd numbers from 1 to 19 using while loop.
i=1
while i <= 19:
print(i)
i = i +2
Example 5 : Write program to find the sum of all the numbers from 0 to 20
i=0
sum=0
Example 6 : Write program to find the sum of all even the numbers from 0 to 20
i=0
sum=0
while i <= 20:
if i%2= =0 :
sum=sum+i
print(sum)
i = i +1
• Infinite Loop is loop, in which condition never becomes false, hence block of code will be
executed infinite number of times.
• An infinite loop is useful in client/server programming, where the server should be
running continuously, so that client can communicate with server, anytime (whenever
required).
• Example 1
n = 10
while True:
print(n)
n = n -1
Here, in this example, the condition specified is the constant value True, so all the time it
is true, no way to make it false, so once it gets into infinite loop, it will never get
terminated.
• Example 2
n = 10
while n>0:
print(n)
n = n +1
In this example, because of the improper condition or wrong counter value, the condition
never becomes false, so loop will never get terminated.
Here initially n=10, condition is true, so loop body statement gets executed, also value of n
is incremented (n=11). Now, again condition is checked, condition is true, again loop body
gets executed. Here no chance of condition becoming true, so loop gets executed infinite
number of times.
While, break
• Sometimes we don’t know, when to end a loop until we get half way through the loop
body. In that case we can write an infinite loop and then use the break statement to jump
out of the loop.
• The break statement terminates the current loop and passes the control to the next
statement, which is immediately after the body of loop
Here break statement is placed within loop, after the if statement & break statement
provides chance to exit the loop, when external condition is generated.
Example:
n=1
while n>0:
print(n)
n = n +1
if n==8:
break
.
Example: Program to take input data from the user until they type done.
while True:
data = input('Enter the data')
if data == 'done':
break
print(data)
print('Done!')
Example:
Program to generate the natural numbers from 1 to 5 except 3
Hint : Skip the iteration if the variable i is 3, but continue with the next iteration
i=0
while i<=5
i=i+1
if i == 3:
continue
print(i)
Example: Program to accept the input string “India” 5 times from the user, if the entered string is
other than India, do not accept it and again ask the user to enter the input.
i=0
while i<=5
str=input(“ Enter the name of your country”)
if str != “India”:
continue
elif str==”India”
print(str)
i=i+1
• Example: Program to find the sum of 5 even numbers taken from the keyboard, if the user
enters odd number do nothing and again ask the user to enter number.
sum=0
count=0
while True:
x=input("Enter a number:")
if x%2!=0:
continue
else:
sum=sum+1
count=count+1
if count==5:
break
print("Sum= ", sum)
i = 0
while i < 4:
i =i+1
print(i)
else: # Executed because no break in
print("Bye bye")
• Example
i = 0
while i < 4:
i += 1
print(i)
break
else: # Not executed as there is a break
print("Bye Bye")
range ( ) function
• range() : range() is in-built function, which is used to generate a series of numbers within a
given range.
• The most common use of range () function is to iterate or to index sequence type (List,
tuple, dictionary, string, etc.) with for and while loop.
Syntax:
range(start, stop, step)
range(start, stop) # By default step size is one
range(stop) # By default start is zero and step size is one.
• This function does not store values in the memory, it only remembers start, step and step
size on the go. To force this, it has to be used with sequence type or for and while loop.
Exercises
• In case of for loop, we know number of times the block of code to be executed or repeated
in prior, so this is called as a definite loop.
• But in case of while loop, it repeats, until some condition becomes False, so it is called as
indefinite loop
• The for-loop is always used in combination with an iterable object, like range or sequence
(that is either a list, a tuple, a dictionary, a set, or a string).
• for loop, iterates over each item of a sequence in order & executes body of loop each time.
• In for loop, it is not required to set the indexing variable beforehand.
• With each iteration, Python automatically increments the index of variable.
Syntax:
Example:
for i in range(1, 6, 2):
print(i)
Output:
0
2
4
Output:
2
5
8
18
10
Output:
3
6
18
Output:
Virat
10.5
6
Dhoni
(5+10j)
Output:
0 Virat
1 10.5
2 6
3 Dhoni
4 (5+10j)
Note: Similarly for loop can be used to iterate through the tuples,
dictionary, sets, strings etc
count = 0
for i in [3, 41, 12.5, -9, 21, 15]:
count = count + 1
print ('Count: ', count)
Output:
Count: 6
• Here, the variable count is initialized to zero before the loop starts.
• for loop runs over each element of the list.
• The iteration variable ‘i’ controls the loop, it causes the loop body to be executed
once for each element in the list.
• For each element of the list, loop body gets executed, so for each element of list,
the 1 is added to value of the count variable. Thus, after completion of all
executions of loop body or iterations, the variable count will hold count of the total
number of elements in the list.
Summing Loop
We can use the for loop to sum up the all-List elements or List items
total = 0
for i in [3, 41, 12.5, -9, 21, 15]:
total = total + i
print ('Total of all the elements in list: ', total)
Output:
Total of all the elements in list: 83.5
• Here, in each iteration, iteration variable ‘i’ contains one particular value of List, for
example, in the 1st iteration, it contains value 3, and in the second iteration, it contains
the 41 and so on.
• For each element of the list, loop body gets executed, so in each iteration, value of the
iteration variable ‘i’ is added to the total variable.
• Thus, after completion of all the iterations, the variable total contains the sum of all
the elements of List
• As the loop is being executed, the variable total, accumulates the sum of the elements;
so, this total variable is sometimes called an accumulator.
• Note: In practise, neither the counting loop nor the summing loop are particularly
useful, because there are built-in functions len() and sum() that compute the number of
items in a list and the total of the items in the list respectively.
largest =0
for i in [3, 41, 12, 9, 74, 15]:
if i > largest:
largest = i
print(' Iteration variable value:', i, ‘largest:’ largest)
print('Largest:', largest)
Output
Iteration variable value: 3 largest: 3
Iteration variable value: 41 largest: 41
Iteration variable value: 12 largest: 41
Iteration variable value: 9 largest: 41
Iteration variable value: 74.5 largest: 74.5
Iteration variable value: 15 largest: 74.5
Largest: 74.5
Minimum Loops
• We can use the for loop, to find the minimum valued element of List.
smallest =10000000
for i in [-3, 41, -12, 9, 74, 15]:
if i < smallest:
smallest=i
print(' Iteration variable value:', i, 'smallest:', smallest)
print('smallest:', smallest)
Example 1:
• For example, consider the following code segment
a=int(input("Enter value for a:"))
b=int(input("Enter the value for b:"))
c=a/b
print(c)
• Let us run the above code, and see output
Output :
Enter value for a:5
Enter the value for b:0
-------------------------------------------------------------------------
-
ZeroDivisionError Traceback (most recent call
last)
ZeroDivisionError: division by zero
• Here because of the wrong input, during runtime error has occurred and error message is
generated, but for the end-user, it is difficult to understand the such type of system-generated
error messages and handle the errors.
• By using try and except statements, we can display our own messages or solution to the user
so that problem can be handled or solved easily.
Consider the example
a=int(input("Enter value for a:"))
b=int(input("Enter the value for b:"))
try:
c=a/b
print(c)
except:
print ("Division by zero is not possible, enter non zero value for b")
Output:
Enter value for a:5
Enter the value for b:0
Division by zero is not possible, enter non zero value for b
1. Import the sys Module: To use sys.exit(), you need to import the sys module at the
beginning of your script.
2. Infinite Loop Example:
o Create a loop that runs indefinitely using while True:.
o Prompt the user for input inside the loop.
3. Check User Input:
o If the user types 'exit', call sys.exit() to terminate the program.
o Otherwise, print the user's input.
python
Copy code
import sys
while True:
print('Type exit to exit.')
response = input()
if response == 'exit':
sys.exit()
print('You typed ' + response + '.')
Explanation of the Example
Functions
• As program grows larger and larger, it becomes very complicated to handle & debug, so
bigger block of code is broken into many small blocks of code (small chunks), where each
small block of code contains the group of statements & performs specific task. This small
block of code is called as function.
• Furthermore, it avoids repetition and makes the code reusable.
• Function is a group of statements or block of code that performs a specific task.
Function runs only when it is called.
• Functions can be either
• built-in or predefined
• user-defined.
• Lamba function
User-defined functions:
• Function is a group of statements or block of code that performs a specific task. Function
runs only when it is called.
• Syntax:
Note: The first line of the function is called function header and remaining part of function
(which is indented) is called body of function
• Function body: Next to define function body: add set of statements that the function
should perform or execute.
• Return statement (optional): End the function with a return statement if the function
has some output. It is optional, if the function does not have any output, it can be
skipped.
• Finally, function is called with its name (fun_name)
Void Functions:
• If function does not return any value (result) to the calling function after performing
some tasks, then such function is known as void function.
• 2 types of void functions
1. Without parameters and without return statement
2. With parameters and without return statement
• Here we have defined function with name cricket using def keyword.
• Aim of function is to print, set of statements, so function does not require any inputs, so
parameter list is empty (without parameters)
• Function body: here function body contains only print statements, function does not output
anything, so return statement is not required, so it skipped.
• Execution: To execute the function, the function has to be called with its name and
arguments to be passed if required. So, here function is called with its name cricket () without
any arguments.
Another example:
Write a user defined function to add 2 numbers and display their sum
#function definition
def fun_add():
num 1= int(input("Enter first number: "))
num2= int(input("Enter second number: "))
y = num1 + num2
print("The sum of 2 numbers is : ", y)
Output:
Enter first number: 5
Enter second number: 6
The sum of 2 numbers is: 11
• Here we have defined function with name fun_add using def keyword.
• Here, addition operation requires the 2 input values, but these values have been accepted from
user within function itself (local variables), so no need to pass the parameters into function
externally. Hence the parameters list is empty
• Function body: here function body contains
Two input statements which accepts two values for num1 & num2.
Addition operation(sum) between num1 & num2
Print statement to print the output.
• In this case, the print statement to display the output, so the optional return statement is skipped.
• To execute the function, the function is called with name fun_add without arguments. In this
case, function uses the local variables for the computation, it does not depend on the external
values, so any arguments are passed into the function call.
fun_add(num1, num2) # function call, here num1 and num2 are arguments
Output:
Enter first number: 5
Enter second number: 6
The sum of 2 numbers is: 11
• In the above program, x and y are called as parameters and num1 & num2 are called as
arguments.
• At the time of function call, the arguments num1 and num2 are passed to this function call.
fun_add(num1, num2)
• The parameter of the function header receives the argument as an input and statements
inside the function body are executed.
• Since python variables are not of specific data type, so we can pass any type of value to
the function as an argument.
Fruitful functions:
• If function returns some result to the calling function after performing some tasks, then
such function is known as Fruitful function
• In the above example, the function fun_add () takes two arguments and returns the result
to the calling function. Here returned value to calling function is stored in the variable s.
• When a function returns something and if it is not stored using the variable, then the return
value will vanish and not be available for the future use.
• Here in case, if we just use the statement fun_add(num1, num2) instead of
s= fun_add(num1, num2), then the value returned from the function is of no use.
• Even, the built-in mathematical functions, random number generating functions etc. are
examples for fruitful functions
import math
math.sqrt(4)
Output: 16
Built in functions
• Built-in functions are the ones, whose functionality is predefined. Here, just function
has to be called whenever the particular task has to be carried out.
• Python has huge collection of built-in functions, this is one of the reasons, why python
is preferred over other languages.
Examples:
max( ) : This function is used to find largest (maximum) value in the object or list. It can be
used for numeric values or even to strings.
1. max('Hello world')
output : 'w' # here w character is having maximum ASCII code
2. max(1, 5 ,21, 17, -8)
output : 21
min( ) : This function is used to find smallest (minimum) value in the list
1. min("hello world")
output : ‘ ‘ #space has least ASCII code here
2. min("helloworld")
output : ‘d ‘ #Character d is having minimum ASCII code
3. min(0.5, -1.2, -4.9, 1.3, 9)
output : -4.9
len(): This function is to find the length of the object. The object can be list, string , tuple
etc.
1. len(“hello how are you?”)
output : 18
Type Conversion:
We can convert the type of the variable/value using functions int(), float(), str() etc.
Function Example
Floating point, string→ integer
• int('20') #integer enclosed within single quotes
Output:20 #converted to integer type
• int(-45)
Output:45
• str(3.14)
Output:'3.14'
str() • str([1,2,3,4])
Output:'[1, 2, 3, 4]'
• str((1,2,3,4))
Output:'(1, 2, 3, 4)'
Output: [1, 2, 3, 4]
Math Functions
• Python provides a set of predefined(inbuilt) mathematical functions through the package
(module) math.
• To use these inbuilt functions, we have to import the math module in our code.
• Few examples of mathematical inbuilt functions are as given below
Function Example
This function is used to find the square root of given number.
import math #importing math package
sqrt() math.sqrt(5)
Output: 2.2360
This function is used to find the power of x to y. Here it takes 2 input values x and y, then
it finds power of x to y
pow() import math
math.pow(2,4)
Output : 8
This function is used to find logarithm of the given number, to the base 10.
import math
log10() math.log10(2)
Output:0.30102
Math constants
pi r=2
import math
Area =math.pi * r*r #Area of circle
print(Area)
Output: 12.56
Output: 2.71828