0% found this document useful (0 votes)
58 views15 pages

Content

The document discusses Python, including that it is a widely used high-level programming language with an emphasis on code readability. It can be used for object-oriented, imperative, and functional programming. Python has a large standard library and supports multiple platforms. Strings in Python are created using quotes and can be concatenated, repeated, indexed, sliced, and compared using operators.

Uploaded by

shruti kotwad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views15 pages

Content

The document discusses Python, including that it is a widely used high-level programming language with an emphasis on code readability. It can be used for object-oriented, imperative, and functional programming. Python has a large standard library and supports multiple platforms. Strings in Python are created using quotes and can be concatenated, repeated, indexed, sliced, and compared using operators.

Uploaded by

shruti kotwad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

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

Python is a widely used high-level, general-purpose, interpreted, dynamic programming


language. Its design philosophy emphasizes code readability, and its syntax allows
programmers to express concepts in fewer lines of code than would be possible in
languages such as C++ or Java. The language provides constructs intended to enable
clear programs on both a small and large scale. Python supports multiple programming
paradigms, including object-oriented, imperative and functional programming or
procedural styles. It features a dynamic type system and automatic memory
management and has a large and comprehensive standard library. Python interpreters
are available for installation on many operating systems, allowing Python code execution
on a wide variety of systems.

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.

Scripting languages are often interpreted (rather than compiled). Primitives


are usually the elementary tasks or API calls, and the language allows them to be
combined into more complex programs. Environments that can be automated through
scripting include software applications, web pages within a web browser, the shells of
operating systems (OS), embedded systems, as wellas numerous games. A scripting
language can be viewed as a domain-specific language for a particular environment; in
the case of scripting an application, this is also known as an extension language.
Scripting languages are also sometimes referred to as very high-level programming
languages, as they operate at a high level of abstraction, or as control languages.

OBJECT ORIENTED PROGRAMMING LANGUAGE


Object-oriented programming (OOP) is a programming paradigm based on the concept
of "objects", which may contain data, in the form of fields ,Often known as attributes;
and code, in the form of procedures, often known as

methods. A distinguishing feature of objects is that an object's procedures can access


and often modify the data fields of the object with which they are associated (objects
have a notion of "this" or "self"). In 00 programming, computer programs are designed
by making them out of objects that interact with one another. There is significant
diversity in object oriented programming, but most popular languages are class-based,
meaning that objects are instances of classes, which typically also determines their type.

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.

Behind The Scene of Python


About the origin of Python, Van Rossum wrote in 1996: Over six years ago, in December
1989, I was looking for a "hobby" programming project that would keep me occupied
during the week around Christmas. My office would be closed, but I had a home
Computer, and not much else on my hands. I decided to write an interpreter for the new
scripting language had been thinking about lately: a descendant of ABC that would
appeal to Unix/C hackers. I chose Python as a working title for the project, being in a
slightly irreverent mood (and a big fan of Monty Python's Flying Circus).

Setup the Path Variable


Begin by opening the start menu and typing in "environment" and select the option
called "Edit the system environment variables." When the "System Properties" window
appears, click on "Environment Variables...". Once you have the "Environment Variables"
window open, direct your focus to the bottom half. You will notice that it controls all the
"System Variables" rather than just this associated with your user. Click on "New..." to
create a new variable for Python.

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,"

Running The Python IDE


Now that we have successfully completed the installation process and added our
"Environment Variable," you are ready to create your first basic Python script. Let's
begin by opening Python's GUI by pressing "Start" and typing "Python" and selecting the
"IDLE (Python GUI)." Once the GUI is open, we will begin by using the simplest directive
possible. This is the "print" directive which simply prints whatever you tell it to, into a
new line.

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 Code Execution

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

Byte code extension is .pyc (compiled python code)

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

 "hello"+"world" “helloworld” #concatenation"


 "hello" 3 "hellohellohello" # repetition
 "hello"[0] "h" # indexing
 "hello"-11"o" # (from end)
 "hello"11:41 "ell" # slicing
 len("hello") 5 # size
 "hello"<"jello" 1 # comparison
 "e" in "hello" 1 # search

Python Operator
>Arithmetic Operator

Operator Meaning Example

+Add two operands or unary plus

x+y

+2

-Subtract right operand from the left or unary minus

x-y

-2

•Multiply two operands x*y

Divide left operand by the right one (always results into

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:

Booleans are either True or False.

Numbers can be integers (1 and 2), floats (1.1 and 1.2), fractions (1/2 and2/3), or even
complex numbers.

Strings are sequences of Unicode characters, eg an HTML document.

Bytes and byte arrays, c.g. a JPEG image file.

Lists are ordered sequences of values.

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

be stored in the reserved memory. Therefore, by assigning different data types to

variables,

you can store integers, decimals or characters in these variables. Ex:

counter = 100# An integer assignment

miles 1000.0# A floating point name="John" # A string

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"+"world" "helloworld" #concatenation

"hello" 3 "hellohellohello" # repetition

"hello"[0] "h" # indexing

"hello"-11"o" (from end)

"hello"[1:4] "ell" # slicing len("hello")5 # size

"hello"<"jello" 1 # comparison

"e" in "hello" 1 #search

Python Operator
>Arithmetic Operator Operator Meaning Example

Add two operands or unary plus

X+Y

+2

-Subtract right operand from the left or unary minus

X+Y

-2

Multiply two operands xy

Divide left operand by the right one (always results into

float) X/Y

%
Modulus-remainder of the division of left operand by the

right

x%y (remainder

of x/y)

//

Floor division-division that results into whole number

adjusted to the left in the number line

x//y

**Exponent-left operand raised to the power of right

***y (x to the power 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

Equal to True if both operands are equal

X=Y

I= Not equal to - True if operands are not equal

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

brackets. Creating a tuple is as simple as putting different comma-separated values.Optionally


you can put these comma-separated values between parentheses also. For example –

tupl= ('physics', 'chemistry', 1997, 2000);

tup2=(1,2,3,4,5);

tup3="a","b","c","d";

Accessing Values in Tuples:

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 -

tup1 = ('physics', 'chemistry', 1997, 2000);

tup2 = (1,2,3,4,5,6,7);

print "tup1[0]:", tup1(0)

print "tup2[1:5]: ", tup2[1:5]

When the above code is executed, it produces the following result-

tup1[0]: physics

tup2[1:5]: [2,3,4,5]

Basic Tuples Operations

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-

Python Expression Results Description

len((1, 2, 3)) 3 Length

(1,2,3) + (4, 5, 6) (1, 2, 3, 4, 5, 6) Concatenation

('Hil',) 4 (Hil', 'Hi!", "Hil', 'Hil") Repetition

3 in (1,2,3) True Membership


for x in (1, 2, 3): print x, 123 Iteration

You might also like