Introducing Python Modules

Similar documents
Dictionaries. By- Neha Tyagi PGT CS KV 5 Jaipur II Shift Jaipur Region. Based on CBSE Curriculum Class -11. Neha Tyagi, KV 5 Jaipur II Shift

PYTHON- AN INNOVATION

Simple Quesries in SQL & Table Creation and Data Manipulation

Data Handing in Python

Insight into Program execution

DATA REPRESENTATION. By- Neha Tyagi PGT CS KV 5 Jaipur II Shift, Jaipur Region. Based on CBSE curriculum Class 11. Neha Tyagi, KV 5 Jaipur II Shift

Understanding Sorting

Python Pandas- II Dataframes and Other Operations

7. MODULES. Rocky K. C. Chang October 17, (Based on Dierbach)

Table Joins and Indexes in SQL

CSCA08 Winter 2018 Week 2: Variables & Functions. Marzieh Ahmadzadeh, Brian Harrington University of Toronto Scarborough

Introduction to Functions. Intro to Computer Science CS1510 Dr. Sarah Diesburg

Copied from: on 3/20/2017

CHAPTER 2: Introduction to Python COMPUTER PROGRAMMING SKILLS

Introducing Python Pandas

Relation Databases. By- Neha Tyagi PGT CS KV 5 Jaipur II Shift Jaipur Region. Based on CBSE Curriculum Class -11. Neha Tyagi, PGT CS II Shift Jaipur

Downloaded from Chapter 2. Functions

Python in 10 (50) minutes

Introduction to: Computers & Programming: Review prior to 1 st Midterm

Introduction to Computer Programming CSCI-UA 2. Review Midterm Exam 1

CSC326 Python Imperative Core (Lec 2)

Unit E Step-by-Step: Programming with Python

Lab 4 Fruitful Functions

Computer System Overview

by Pearson Education, Inc. All Rights Reserved. 2

Fun with functions! Built-in and user-defined functions

Here n is a variable name. The value of that variable is 176.

What is a function? "The Practice of Computing Using Python", Punch & Enbody, Copyright 2013 Pearson Education, Inc.

7. C++ Class and Object

Ch.3: Functions and branching

Module 10: Imperative Programming, Modularization, and The Future

The design recipe. Readings: HtDP, sections 1-5. (ordering of topics is different in lectures, different examples will be used)

Exam 1 Format, Concepts, What you should be able to do, and Sample Problems

Basics of Object Oriented Programming. Visit for more.

Functions!!! Why functions? Functions provide good way to design systems!

Ch.3: Functions and branching

COMP1730/COMP6730 Programming for Scientists. Data: Values, types and expressions.

JAVA GUI PROGRAMMING REVISION TOUR III

Writing Functions. Reading: Dawson, Chapter 6. What is a function? Function declaration and parameter passing Return values Objects as parameters

Built-in Types of Data

A A B U n i v e r s i t y

Python Workshop. January 18, Chaitanya Talnikar. Saket Choudhary

ChAmElEoN Parse Tree

FUNCTION PARAMETER AND ARGUMENT

7/8/10 KEY CONCEPTS. Problem COMP 10 EXPLORING COMPUTER SCIENCE. Algorithm. Lecture 2 Variables, Types, and Programs. Program PROBLEM SOLVING

Defining Functions. turning expressions into functions. writing a function definition defining and using modules

Python 1: Intro! Max Dougherty Andrew Schmitt

Introduction to Python

Babes-Bolyai University

Introduction to: Computers & Programming Defining Identifiers: Objects with Names

Python Day 3 11/28/16

Java Bytecode (binary file)

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

Getting Started. Office Hours. CSE 231, Rich Enbody. After class By appointment send an . Michigan State University CSE 231, Fall 2013

Lecture 4. Defining Functions

Overview. - General Data Types - Categories of Words. - Define Before Use. - The Three S s. - End of Statement - My First Program

Introduction to Python Programming

Chapter 10. Class & Objects in JAVA. By: Deepak Bhinde PGT Com.Sc.

More Data Types. The Char Data Type. Variable Declaration. CS200: Computer Science I. Module 14 More Data Types

Module 01: Introduction to Programming in Python

Scripting Languages. Python basics

Python allows variables to hold string values, just like any other type (Boolean, int, float). So, the following assignment statements are valid:

Accelerating Information Technology Innovation

Chapter 8: Creating Your Own Type Classes

There are four numeric types: 1. Integers, represented as a 32 bit (or longer) quantity. Digits sequences (possibly) signed are integer literals:

Lecture 17: Classes (Chapter 15)

Functions with Parameters and Return Values

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #34. Function with pointer Argument

Lecture 7: Functions. CS1068+ Introductory Programming in Python. Dr Kieran T. Herley 2018/19. Department of Computer Science University College Cork

COMP1730/COMP6730 Programming for Scientists. Functions

Lecture 8: Euler s Methods

Python I. Some material adapted from Upenn cmpe391 slides and other sources

Fundamentals of Programming Session 25

7. (2 pts) str( str( b ) ) str '4' will not compile (single, double, or triple quotes

Step by step set of instructions to accomplish a task or solve a problem

The L Line. The Express Line to Learning. Wiley Publishing All Rights Reserved.

Introduction to computers and Python. Matthieu Choplin

CS1 Lecture 3 Jan. 18, 2019

Java Methods. Lecture 8 COP 3252 Summer May 23, 2017

Python for C programmers

THE AUSTRALIAN NATIONAL UNIVERSITY Mid Semester Examination September COMP1730 / COMP6730 Programming for Scientists

Accelerating Information Technology Innovation

06/11/2014. Subjects. CS Applied Robotics Lab Gerardo Carmona :: makeroboticsprojects.com June / ) Beginning with Python

4. Modules and Functions

CS1 Lecture 3 Jan. 22, 2018

We have written lots of code so far It has all been inside of the main() method What about a big program? The main() method is going to get really

Lecture 1. basic Python programs, defining functions

Key Differences Between Python and Java

An Introduction to Python for KS4!

ENCM 339 Fall 2017 Lecture Section 01 Lab 9 for the Week of November 20

PYTHON. Varun Jain & Senior Software Engineer. Pratap, Mysore Narasimha Raju & TEST AUTOMATION ARCHITECT. CenturyLink Technologies India PVT LTD

Programming in C. main. Level 2. Level 2 Level 2. Level 3 Level 3

Objects and Classes. 1 Creating Classes and Objects. CSCI-UA 101 Objects and Classes

Lecture 02, Fall 2018 Friday September 7

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

Lecture 4: Defining Functions (Ch ) CS 1110 Introduction to Computing Using Python

Review Sheet for Midterm #1 COMPSCI 119 Professor William T. Verts

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.

Statements 2. a operator= b a = a operator b

SOFT 161. Class Meeting 1.6

Transcription:

Introducing Python Modules Based on CBSE Curriculum Class -11 By- Neha Tyagi PGT CS KV 5 Jaipur II Shift Jaipur Region Neha Tyagi, PGT CS II Shift Jaipur

Introduction A book is generally divided into chapters. Why? If it is not divided into chapters, reading will be boring and problematic. Similarly, a big program is generally divided into small units, which are known as modules. The process of dividing a big program into small modules is known as modularity. A module is itself an individual unit.

Introduction Modularity decreases complexity of a program. Modularity also enhance the capability of Reusability. In this chapter we will discuss modularity in python and about python modules.

Functions Imagine a Math s formula say 3x 2 x = 1 will result into 3 X 1 2 = 3 x = 2 will result into 3 X 2 2 = 12 x = 3 will result into 3 X 3 2 = 27 means f(x) = 3x 2 We can say f(x) = 3x 2 is a function where function is f, x is its argument and 3x 2 is its functionality. Function completes its working and afterwards returns a result. Programming languages also supports functions. A function- Can have arguments. Can perform Functionality. Can return result. For exdef Calc(x): r = 3*x**2 return r

Functions def is the keyword to declare a function. calc is name of function. Carefully see the last exampleresult Varibale inside ( ) is argument or parameter. colon : specifies end of line and starting of function block. The block contains whole functionality of the function. Here r = 3 * x ** 2 is the functionality of calc function. The part which is not inside indentation is not the part of function. return statement returns the computed result.

Functions Calling Function calling statement or syntax <FunctionName>(<ValueOfArgumentToBePassed>) def Calc(x): r = 3*x**2 return r To call the function calc you need to write following statement- Calc(4) or A=5 Calc(A)

Python Function Type In Python, functions are of 3 types- Built-in functions : These are ready to use pre defined functions. For ex- len( ), type( ), int( ), input( ) etc. 1. Functions in Modules : These functions existes in modules. To use such functions, you need to first import the concerned module. like sin( ) in math module. 2. User defined functions : These are developed by programmer.

Structure of Python Module A Python Module contains several things other than functions. A Python file (.py file) can contain following objects- Docstring : Triple Quoted comments which are important for documentation. Variables and constants : labels for data. Classes : Blue print for objects. Objects : Instances of classes. Statements : Instructions Functions :Group of instructions Therefore we can say that if there is a module named ABC then there should be a file named ABC.py. Module is an individual unit of data and code. It has the feature of reusability. It can depend on other modules also.

Python Module -Structure docstring starts and ends with triple quotes. This module has 2 functions and 2 docstrings. Importing module. Using object of module.

Python Module-Structure help(<modulename>) is used to see complete documentation of module. Facts of docstring : First letter of a line should be capital. Second line empty. Information in third line. dir (<ModuleName>) shows name of all objects of a module.

Importing module in a Python program Import statement can be used in two forms- 1. Importng complete moduleimport module1, module 2,.... For ex: >>>import math >>>import math,time etc To use it s object then- <modulename>.<functionname> 2. Importing selected objects from a module.- from <module> import<objectname1>,<>... Here, first pi value showed error. But when it is used after importing math module then all errors gets resolved.

Namespace A namespace is a place to keep all names. It can understand with following example- Suppose students from different KVs are participating in regional sports meet. If a name say Rahul is called- There may be many students with the name Rahul which will create confusion. Correct way of calling here should be Rahul from KV 5 Jaipur. Hence, KV 5 Jaipur is a namespace for Rahul here. This way of namespace resolves confusion. Similarly in python, namespace is an environment to keep logical group of related objects. Python creates a namespace with the name of module itself. When two modules comes together then it gives a manner to write two similar objects, which is as under- <ModuleName>.<ObjectName> Example : >>>math.sqrt(4)

Processing of import <module> command When you run import <module> command, following tasks takes place- Code of imported module executed after interpretation. All programs and variables of the imported modules comes in the present program. A namespace is set up with the name of imported module itself. Processing of from <module> import <object>command When you run from<module> import <object> command, following tasks takes place- Code of imported module executed after interpretation. Only selected (asked for) programs and variables of the imported modules comes in the present program. No new namespace is created. Imported objects appends in the present namespaceह

Thank you Please follow us on our blog www.pythontrends.wordpress.com Neha Tyagi, KV 5 Jaipur II Shift