0% found this document useful (0 votes)
28 views17 pages

Python Programming Guide and Acknowledgments

Uploaded by

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

Python Programming Guide and Acknowledgments

Uploaded by

jmadhur57
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Acknowledgment

I wish to express my profound gratitude to the almighty with whose grace and
blessing, I have been able to complete another chapter of my life.

I would like to extend my appreciation to my industrial supervisor, Mr. Tarun Jain for
his advices and patiently guiding me through while I working here as a trainee .I very
much appreciate for their entire kindness helping and teaching me when I am working
there. I am very lucky to have such a helpful colleagues and I never felt left out in any
situation.

I wish learnt a lot of valuable things while working here. I realize that learning is never
the same when it comes to practice. I wish to extend my sincere gratitude to Mr.
Aashish Sir and faculty of CSE department for their guidance, encouragement and
valuable suggestion which proved extremely useful and helpful in completion of this
industrial training.

I find no words to acknowledgment the sacrifice, help and inspiration rendered by my


parents to take up this study.

With thanks to all,


Madhur Jain

220130800032

5th Semester

Computer Engineering
Table of Contents

i. Introduction ………………….....................................................1
ii. Features ………………………………………………………………... 1
iii. History …………………………………………………………………..2
iv. Python Version ……………………………………………………..…2
v. Running the Python IDLE……………………………………………3
vi. Python Code Execution ……………………………………………..3
vii. Data Type………………………………………………………………..4
viii. Variable ………………………………………………………………....5
ix. String ………………………………………………………………….5-6
x. Function………………………………………………………………....6
xi. Tuple …………………………………………………………………...7-8
xii. List……………………………………………………………………..8-10
xiii. Loops………………………………………………………………....11-12
xiv. Conditional Statement……………………………………….....13-14
xv. Scope of Python ………………………………………………….…..14
xvi. What can be do with Python ?…………………………………….14
xvii. Who uses Python today?…………………………………………....15
xviii. Why do people use Python ?……………………………………….15
Python

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


language. Python programming language was developed by Guido Van Rossum in 1991.
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 support multiple programming pattern, including object oriented, imperative and

functional or procedural programming styles. Python makes the development and


debugging fast because there is no compilation step included in python development
and edit-test-debug cycle is very fast.

Python Features
1. Easy to Learn and Use: Python is easy to learn and use. It is developer-friendly and high
level programming language.
2. Expressive Language: Python language is more expressive means that it is more
understandable and readable.
3. Interpreted Language: Python is an interpreted language i.e. interpreter executes the code
line by line at a time. This make debugging easy and thus suitable for beginners.
4. Cross-platform Language: Python can run equally on different platforms such as
Windows, Linux, Unix and Macintosh etc. So, we can say that Python is a portable language.
5. Free and Open Source: Python language is freely available at official web address. The
source-code is also available. Therefore it is open source.
6. GUI Programming Support: Graphical user interfaces can be developed using Python.
7. Integrated: It can be easily integrated with languages like C, C++, JAVA etc.
8. Large Standard Library: Python has a large and broad library and provides rich set of
module and functions for rapid application development.
9. Object-Oriented Language: Python supports object oriented language and concepts of
classes and objects come into existence.

1
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 capable of
exception handling and interfacing with the Amoeba operating system.

Python Version List


Python programming language is being updated regularly with new features and supports.
There are lots of updations in python versions, started from 1994 to current release.

2
Running The Python IDLE

1. Install Python (if not installed):


If Python is not installed on your system, follow these steps:
• Go to the official Python website.
• Download the latest version of Python for Windows.
• During installation, make sure to check the box that says “Add Python to PATH” at the
beginning of the installation wizard.
• After installation completes, Python and IDLE should be ready to use.

2. Open Python IDLE:


• Once Python is installed, you can open IDLE by following these steps:
• Press the Windows key on your keyboard to open the Start Menu.
• Type IDLE into the search bar. You should see something like “IDLE (Python 3.x 64-bit)”
(where x represents the version number you installed).
• Click on it to launch the Python IDLE.

3. Using Python IDLE:


• Once IDLE is open, you’ll see the Python Shell where you can directly type and run
Python code interactively.
• To run Python code directly in the shell, just type it and press Enter.
• To create a Python script, go to File > New File, write your code, and then save the file
with a .py extension.
• To run a saved Python script, press F5 or go to Run > Run Module.

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)

3
Data Type

In Python, a data type refers to the classification of data based on the kind of value it holds.
Data types determine the operations that can be performed on the data and the kind of
values the data can store. Python is a dynamically typed language, meaning you do not
need to explicitly declare a variable’s type when you create it, and the type can change
during execution.
Each variable or value in Python has a specific data type that defines the nature of the data.
The data type essentially tells Python how to handle and store the data in memory.

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 and 2/3), or even complex
numbers.

Strings are sequences of Unicode characters, e.g. an HTML document.

Range represents a sequence of numbers, typically used in loops. It generates numbers in a specific range

Lists are ordered sequences of values.

Tuples are ordered, immutable sequences of values.

Sets are unordered bags of values.

None Represents the absence of a value or a null value (e.g., None)

4
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 acollection
of letters, the term makes sense.

All the letters, numbers, and symbols in this book could be string. For

that matter, your name could be a string, and so couldyour address.

Creating Strings

In Python, we create a string by putting quotes around text. For example, we could take our otherwise
useless

• "hello"+"world" "helloworld" # concatenation

5
• "hello"*3 "hellohellohello" # repetition

• "hello"[0] "h" # indexing

• "hello"[-1] "o" # (from end)


• "hello"[1:4] "ell" # slicing

• len("hello") 5 # size

• "hello" < "jello" 1 # comparison


• "e" in "hello" 1 # search

Function
Function blocks begin with the keyword def followed by the function name and parentheses (( )).

Any input parameters or arguments should be placed within these parentheses. You can also define
parameters inside these parentheses.

The first statement of a function can be an optional statement – the documentation string of the function.

The code block within every function starts with a colon (:) and is indented.

The statement return [expression] exits a function, optionally passing back an expression to the caller. A
return statement with no arguments is the same as return None.

Syntax:

def function_name(parameters):
function-suite
return[expression]

Example:

def printme(str):
print(“this print a passed string into this function”)

Return

1. # Function definition is here def printme( str ):

“This prints a passed string into this function” print str return;

# Now you can call printme function printme(“I’m first call to user defined function!”) printme(“Again second
call to the same function”)

6
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.

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

('Hi!',) * 4 ('Hi!', 'Hi!', 'Hi!', 'Hi!') Repetition

3 in (1, 2, 3) True Membership

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

7
Built-in Tuple Functions

Python includes the following tuple functions −

SN Function with Description

1 cmp(tuple1, tuple2) Compares elements of both tuples.

2 len(tuple) Gives the total length of the tuple.

3 max(tuple) Returns item from the tuple with max value.

4 min(tuple) Returns item from the tuple with min value.

5 tuple(seq) Converts a list into tuple.

List
The list is a most versatile datatype available in Python which can be written as a list of comma-
separated values (items) between square brackets. Important thing about a list is that items in a
list need not be of the same type.

Creating a list is as simple as putting different comma-separated values between

square brackets. For example − list1 = ['physics', 'chemistry', 1997, 2000]; list2 = [1, 2, 3,

4, 5 ]; list3 = ["a", "b", "c", "d"];

Similar to string indices, list indices start at 0, and lists can be sliced, concatenated and so on.

Accessing Values in Lists:


To access values in lists, use the square brackets for slicing along with the index or indices to

obtain value available at that index. For example − list1 = ['physics', 'chemistry', 1997, 2000];

list2 = [1, 2, 3, 4, 5, 6, 7 ]; print "list1[0]: ", list1[0] print "list2[1:5]: ", list2[1:5]

8
Output: list1[0]: physics

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

Update: list = ['physics', 'chemistry', 1997, 2000]; print

"Value available at index 2 : " print list[2] list[2] = 2001; print

"New value available at index 2 : " print list[2]

Output: Value available at index 2 :


1997 New value available at index 2 :
2001

Delete: list1 = ['physics', 'chemistry', 1997, 2000]; print

list1 del list1[2]; print "After deleting value at index 2 : " print

list1

['physics', 'chemistry', 1997, 2000] Output:

After deleting value at index 2 :['physics',

'chemistry', 2000]

Basic List Operation


Python Expression Results Description

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

[1, 2, 3] + [4, 5, 6] [1, 2, 3, 4, 5, 6] Concatenation

['Hi!'] * 4 ['Hi!', 'Hi!', 'Hi!', 'Hi!'] Repetition

3 in [1, 2, 3] True Membership

for x in [1, 2, 3]: print x, 123 Iteration

9
Built-in List Functions:
S Function with Description
N

1 cmp(list1, list2) Compares elements of both lists.

2 len(list) Gives the total length of the list.

3 max(list) Returns item from the list with max value.

4 min(list) Returns item from the list with min value.

5 list(seq) Converts a tuple into list.

10
Loop definition
Programming languages provide various control structures that allow for more complicated
execution paths.

A loop statement allows us to execute a statement or group of statements multiple times. The
following diagram illustrates a loop statement −

> Greater than - True if left operand is greater than the right x> y

< Less than-True if left operand is less than the right x<y

== Equal to - True if both operands are equal x==y

!= 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
>= x>= y
right

x<=y
<= Less than or equal to – True if left operand is less than or equal to the right

11
Python programming language provides following types of loops to handle looping
requirements.

Loop Type Description

while loop Repeats a statement or group of statements while a given


condition is TRUE. It tests the condition before executing theloop
body.

for loop Executes a sequence of statements multiple times andabbreviates


the code that manages the loop variable.

nested loops You can use one or more loop inside any another while, for or
do..while loop.

Loop Example:
For Loop:

>>> for mynum in [1, 2, 3, 4, 5]:


print (“Hello”, mynum )

Hello 1
Hello 2
Hello 3
Hello 4
Hello 5
While Loop:

>>> count = 0
>>>while(count< 4):
print( “The count is:” count = count + 1)

The count is: 0


The count is: 1
The count is: 2
The count is: 3
12
Conditional Statements:

Decision making is anticipation of conditions occurring while execution of the program and specifying
actions taken according to the conditions.

Decision structures evaluate multiple expressions which produce TRUE or FALSE as


outcome. You need to determine which action to take and which statements to execute if
outcome is TRUE or FALSE otherwise.

Python programming language provides following types of decision making statements. Click the
following links to check their detail.

Statement Description

if statements An if statement consists of a boolean expression


followed by one or more statements.

if...else statements An if statement can be followed by an optional else


statement, which executes when the boolean expression
is FALSE.

nested if statements You can use one if or else if statement


inside another if or else if statement(s).

13
Example:
If Statement:
a=33

b=200

if b>a:

print(“b”)

If...Else Statement:
a=200
b=33
if b>a:

print(“b is greater than a”)

else:
print(“a is greater than b”)

SCOPE OF PYTHON

1 - Science
- Bioinformatics

2 - System Administration
- Unix

- Web logic
- Web sphere

3 - Web Application Development

What Can We do With Python?

1 System programming
2 Graphical User Interface
3 Internet Scripting
4 Component Integration
14
WHO USES PYTHON TODAY?
• Python is being applied in real revenue-generating products by real companies.
• Google makes extensive use of Python in its web search system, and employs Python’s
creator.
• Intel, Cisco, Hewlett-Packard, Seagate, Qualcomm, and IBM use Python for hardware testing.
• ESRI uses Python as an end-user customization tool for its popular GIS mapping products.

WHY DO PEOPLE USE PYTHON?


• The YouTube video sharing service is largely written in Python.

• Python is object-oriented o Structure supports such concepts as


polymorphism, operation overloading, and multiple inheritance.
• Indentation o Indentation is one of the greatest future in Python.
• It's free (open source) o Downloading and installing Python is free and
easy o Source code is easily accessible
• It's powerful o Dynamic typing o Built-in types and tools o Library
utilities
o Third party utilities (e.g. Numeric, NumPy, SciPy) o
Automatic memory management
• It's portable o Python runs virtually every major platform used today
o As long as you have a compatible Python interpreter installed,
Python programs will run in exactly the same manner, irrespective of
platform.

15

Common questions

Powered by AI

Python’s dynamic typing and native data types provide flexibility and efficiency in memory and processing management. Dynamic typing allows variables to be reassigned to different data types, which optimizes memory usage as the type can adjust as needed during runtime . Additionally, the variety of native data types—such as lists, tuples, and dictionaries—are tailored for specific operations, enabling efficient data handling and storage . This adaptability aids programmers in writing concise code without explicit memory management, thereby increasing processing efficiency and development speed.

Python is ideal for beginners due to its straightforward syntax that mirrors natural language, making it easy for newcomers to understand and write code without prior programming experience . Its interpreted nature simplifies testing and debugging by providing immediate feedback on code interaction, essential for learning and growth . The extensive standard library simplifies complex functionalities, allowing beginners to implement advanced features with minimal code, thereby offering a rich learning ' sandbox' tuned for experimentation and immediate application of programming concepts .

Python handles code execution through its interpreted, bytecode-compiled approach, where source code (.py) is first converted into bytecode (.pyc) and then executed on the Python Virtual Machine . This process eliminates the need for platform-specific compilation, enhancing cross-platform compatibility. As Python bytecode runs consistently across different operating systems, developers can write Python code on one platform and execute it on another without modification, ensuring uniform behavior and performance across diverse environments .

Tuples in Python are sequences of immutable Python objects, meaning that once a tuple is created, its values cannot be changed . They are similar to lists, which are mutable and can be modified post-creation. Tuples use parentheses for their declaration, whereas lists are defined using square brackets . This immutability characteristic makes tuples suitable for use as keys in dictionaries and ensures that the data within them remains constant throughout the program execution.

Python is considered powerful and versatile primarily due to its design philosophy that emphasizes code readability, allowing programmers to express concepts in fewer lines of code compared to languages like C++ or Java . It is also an interpreted language, making debugging easier without a compilation step, which speeds up the development and testing cycle . Python supports multiple programming paradigms, including object-oriented, imperative, and functional programming, offering a flexible structure for a variety of applications . Additionally, Python's vast standard library provides extensive modules and functions for rapid application development , and its open-source nature makes it freely available and easily modifiable .

Python’s evolution from its inception as a successor to the ABC language, with enhancements for exception handling and system interfacing, has helped it maintain relevance by focusing on practical, real-world applicability . Initiated by Guido van Rossum to interface with the Amoeba OS, Python has expanded its scope to include comprehensive libraries and tools for web development, data analytics, automation, and more . Continuous updates and feature introductions, reflecting community needs and technological advances, ensure that Python adapts to evolving programming challenges, from enabling machine learning to supporting micro-services architectures.

Python’s ability to easily integrate with other programming languages like C, C++, and Java significantly enhances its utility in software development. This integration allows developers to leverage Python's concise and readable syntax for scripting and rapid application development, while simultaneously using performance-critical components developed in C or C++ for tasks that demand high efficiency . Such interoperability facilitates a polyglot programming environment where Python acts as the glue language to bind diverse systems, thus improving code reuse, minimizing redundancy, and optimizing execution performance.

Python's emphasis on code readability and its clean, expressive syntax offer significant cognitive benefits to developers, particularly newcomers to programming. The language avoids complex syntax rules, enabling developers to focus on logical constructs rather than syntactical correctness . This simplicity reduces cognitive load, decreasing the likelihood of syntax errors and enhancing comprehension of code structures. Consequently, beginners can quickly grasp programming concepts, accelerating learning and application development, while experienced developers can efficiently interpret and maintain code .

Python's industrial relevance is demonstrated by its adoption across various commercial sectors for revenue-generating and mission-critical applications. Google extensively uses Python in its web search system, highlighting its capability to handle large-scale, data-intensive environments . Companies like Intel, Cisco, and IBM utilize Python for hardware testing, showcasing its effectiveness in system automation and reliability . Moreover, ESRI’s use of Python for customizing GIS mapping products illustrates its versatility in tailoring applications for specific industry needs . This widespread use across diverse technological arenas underscores Python's robustness, portability, and comprehensive library support, making it indispensable for both enterprise-level applications and niche solutions.

Python's conditional statements, such as if, elif, and else, are crucial in decision-making processes within programs, enabling the execution of different code blocks based on boolean conditions . They allow programmers to model complex logic flows and perform operations based on varying data inputs and conditions, enhancing program interactivity and functionality . These constructs facilitate responsive program architectures that adapt to different runtime scenarios, thereby providing flexibility and dynamic control flow necessary for building robust applications.

You might also like