CH - 1 Getting Started With Python
CH - 1 Getting Started With Python
Python shell
. can be used in two ways, viz.,
interactive mode and script mode. Where
Interactive Mode, as the name suggests,
allows us to interact with OS; script mode
let us create and edit python source file.
Q7. What is Interactive mode in Python?
OPERATOR DESCRIPTION
.
** Exponentiation (raise to the power)
+, - Unary plus and minus
*, /, %, / / Multiply, divide, modulo and floor division
+,- Addition and Subtraction
<,<=, >, >= Comparison operator
%=, /=, //=.+-, -=, *= Assignment operators
not, and, or Logical operators
Q18. What are the different types of statements?
Module:
A module is a file containing Python definitions (i.e.
functions) and statements. Standard library of Python is
extended as module(s)
. to a Programmer. Definitions from
the module can be used into code of Program. To use these
modules in a program, programmer needs to import the
module. Once we import a module, we can reference (use)
to any of its functions or variables in our code. There are
two ways to import a module in our program, they are :
import
from
Q23. What is import statement in Python?
Import: It is simplest and number")
most common way to use y = math.sqrt(x)
modules in our code. a = math.pow(x,2)
Syntax: print "Square Root
.
import modulename1 [, value=",y
module name 2, ---------] print "square value=",a
Example: Input any number output:
and to find square and Enter any number25
square root. Square Root value= 5.0
Example: square value= 625.0
import math
x = input ("Enter any
Q24. What is from statement in Python?
From statement: It is used to get a x=input("Enter any number")
specific function in the code y=sqrt(x) #without using math
instead of complete file. If we know a=pow(x,2) #without using math
beforehand which function(s), we print "Square Root value =",y
will be needing, then we may use print "square value =",a
'from'. For modules having large Enter any number100
number of functions,
. it is Square Root value = 10.0
recommended to use from instead square value = 10000.0
of import. The functions available in math
Syntax module are:
>>> from modulename import ceil() floor() fabs() exp() log()
functionname [, functionname…..] log10() pow() sqrt() cos() sin() tan()
from modulename import * degrees() radians()
will import everything from the file. Some functions from random
Example: Input any number and to module are:
find square and square root. random() randint() uniform()
Example: randrange()
from math import sqrt,pow
Q25. What are built-in functions in Python?