Content
Content
ACKNOWLEDGEMENT
It is our proud privilege and duty to acknowledge the kind of help and
guidance received from several people in preparation of this report. It would not have
been possible to prepare this report in this form without their valuable help,
cooperation and guidance. First and foremost, we wish to record our sincere gratitude
to Prof., Dr. Sashi Kumar Sharma for his constant support and encouragement in
preparation of this report and for making available library and laboratory facilities
needed to prepare this report.
The seminar on "Python 3" was very helpful to us in giving the necessary
background information and inspiration in choosing this topic for the seminar. Their
contributions and technical support in preparing this report are greatly acknowledged.
Last but not the least, we wish to thank our parents for financing our studies in this
college as well as for constantly encouraging us to learn engineering. Their personal
sacrifice in providing this opportunity to learn engineering is gratefully acknowledged
PYTHON
Scripting Language :
A scripting or script language is a programming language that supports scripts ,programs
written for a special run-time environment that automate the execution of tasks that
could alternatively be executed one-by-one by a human operator.
History
Python was conceived in the late 1980s, and its implementation was started in
December 1989 by Guido van Rossum at CWI in the Netherlands as a successor to the
ABC language (itself inspired by SETL) capable of exception handling and interfacing with
the Amoeba operating system. Van Rossum is Python's principal author, and his
continuing central role in deciding the direction of Python is reflected in the title given to
him by the Python community, benevolent dictator for life (BDFL).
"Python is an experiment in how much freedom programmers need. Too much freedom
and nobody can read another's code; too little and expressiveness is endangered."-
Guido van Rossum.
Simply enter a name for your Path and the code shown below. For the purposes of this
example we have installed Python 2.7.3, so we will call the path: "Pythonpath." The
string that you will need to enter is: "C:\Python27\C\Python27\Scripts,"
Start by typing a print directive like the one shown in the image below or copy and paste
this text then press "Enter": print ("Congratulations on executing your first print
directive!").
Python's traditional runtime execution model: source code you type is translated to byte
code, which is then run by the Python Virtual Machine. Your code is automatically
compiled, but then it is interpreted. Source code extension is .py
STRING
In programming terms, we usually call text a string. When you think of a string as a
collection of letters, the term makes sense. All the letters, numbers, and symbols in this
book could be a string For that matter, your name could be a string, and so could your
address.
Creating Strings
In Python, we create a string by putting quotes around text. For example, we could take
ourotherwise useless
Python Operator
>Arithmetic Operator
x+y
+2
x-y
-2
float)
X/Y
DATA TYPE
Data types determine whether an object can do something, or whether it just would not
make sense. Other programming languages often determine whether an operation
makes sense for an object by making sure the object can never be stored somewhere
where the operation will be performed on the object (this type system is called static
typing). Python does not do that. Instead it stores the type of an object with the object,
and checks when the operation is performed whether that operation makes sense for
that object (this is called dynamic typing).
Python has many native data types. Here are the important ones:
Numbers can be integers (1 and 2), floats (1.1 and 1.2), fractions (1/2 and2/3), or even
complex numbers.
Tuples are ordered, immutable sequences of values. Sets are unordered bags of values.
Variable
Variables are nothing but reserved memory locations to store values. This means that
when you create a variable you reserve some space in memory. Based on the data type
of a variable, the interpreter allocates memory and decides what can
variables,
String
In programming terms, we usually call text a string. When you think of a string as a collection of
letters, the term makes sense.All the letters, numbers, and symbols in this book could be a
string. For that matter, your name could be a string, and so could your address.
Creating Strings
In Python, we create a string by putting quotes around text. For example, wecould take our
otherwise useless
"hello"<"jello" 1 # comparison
Python Operator
>Arithmetic Operator Operator Meaning Example
X+Y
+2
X+Y
-2
float) X/Y
%
Modulus-remainder of the division of left operand by the
right
x%y (remainder
of x/y)
//
x//y
Comparison Operator
> Greater that -True if left operand is greater than the right x>y
< Less that - True if left operand is less than the rightx<y
X=Y
x>=
y<=
Greater than or equal to True if left operand is greater than or equal to the right
x>=
y<=
Less than or equal to - True if left operand is less than or equal to the right
Logical Operator
Operator Meaning Example and True if both the operands are true x and yor True if either of the
operands is true x or y not True if operand is false (complements the operand) notx.
Tuples
A tuple is a sequence of immutable Python objects. Tuples are sequences, just like lists. The
differences between tuples and lists are, the tuples cannot be changed unlike lists and tuples use
parentheses, whereas lists use square
tup2=(1,2,3,4,5);
tup3="a","b","c","d";
To access values in tuple, use the square brackets for slicing along with the index or indices to
obtain value available at that index. For example -
tup2 = (1,2,3,4,5,6,7);
tup1[0]: physics
tup2[1:5]: [2,3,4,5]
Tuples respond to the + and operators much like strings; they mean concatenation and
repetition here too, except that the result is a new tuple, not a string. In fact, tuples respond to
all of the general sequence operations we used on strings in the prior chapter-