Introducing Python Modules

Size: px
Start display at page:

Download "Introducing Python Modules"

Transcription

1 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

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

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

4 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

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

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

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

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

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

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

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

12 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)

13 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ह

14 Thank you Please follow us on our blog Neha Tyagi, KV 5 Jaipur II Shift

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

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 Dictionaries Based on CBSE Curriculum Class -11 By- Neha Tyagi PGT CS KV 5 Jaipur II Shift Jaipur Region Introduction Python provides us various options to store multiple values under one variable name.

More information

PYTHON- AN INNOVATION

PYTHON- AN INNOVATION PYTHON- AN INNOVATION As per CBSE curriculum Class 11 Chapter- 2 By- Neha Tyagi PGT (CS) KV 5 Jaipur(II Shift) Jaipur Region Python Introduction In order to provide an input, process it and to receive

More information

Simple Quesries in SQL & Table Creation and Data Manipulation

Simple Quesries in SQL & Table Creation and Data Manipulation Simple Quesries in SQL & Table Creation and Data Manipulation 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

More information

Data Handing in Python

Data Handing in Python Data Handing in Python As per CBSE curriculum Class 11 Chapter- 3 By- Neha Tyagi PGT (CS) KV 5 Jaipur(II Shift) Jaipur Region Introduction In this chapter we will learn data types, variables, operators

More information

Insight into Program execution

Insight into Program execution Insight into Program execution Based on CBSE curriculum Class 11 By- Neha Tyagi PGT CS KV 5 Jaipur II Shift, Jaipur Region Introduction As we know that computer works on machine level language which is

More information

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

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 DATA REPRESENTATION Based on CBSE curriculum Class 11 By- Neha Tyagi PGT CS KV 5 Jaipur II Shift, Jaipur Region Neha Tyagi, KV 5 Jaipur II Shift Introduction As we know that computer system stores any

More information

Understanding Sorting

Understanding Sorting Understanding Sorting Based on CBSE Curriculum Class -11 By- Neha Tyagi PGT CS KV 5 Jaipur II Shift Jaipur Region INTRODUTION Generally, sorting means to categorize the objects as per their groups. A Computer

More information

Python Pandas- II Dataframes and Other Operations

Python Pandas- II Dataframes and Other Operations Python Pandas- II Dataframes and Other Operations Based on CBSE Curriculum Class -11 By- Neha Tyagi PGT CS KV 5 Jaipur II Shift Jaipur Region Neha Tyagi, KV 5 Jaipur II Shift Introduction In last chapter,

More information

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

7. MODULES. Rocky K. C. Chang October 17, (Based on Dierbach) 7. MODULES Rocky K. C. Chang October 17, 2016 (Based on Dierbach) Objectives Explain the specification of modules. Become familiar with the use of docstrings in Python. Explain the use of modules and namespaces

More information

Table Joins and Indexes in SQL

Table Joins and Indexes in SQL Table Joins and Indexes in SQL 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 Sometimes we need an information

More information

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

CSCA08 Winter 2018 Week 2: Variables & Functions. Marzieh Ahmadzadeh, Brian Harrington University of Toronto Scarborough CSCA08 Winter 2018 Week 2: Variables & Functions Marzieh Ahmadzadeh, Brian Harrington University of Toronto Scarborough Administrative Detail Tutorials and practicals start this week Inverted lecture starts

More information

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

Introduction to Functions. Intro to Computer Science CS1510 Dr. Sarah Diesburg Introduction to Functions Intro to Computer Science CS1510 Dr. Sarah Diesburg Review So far, most of our programs have retrieved data from the keyboard and written data to the screen Data must be entered

More information

Copied from: https://www.cs.hmc.edu/twiki/bin/view/cs5/lab1b on 3/20/2017

Copied from: https://www.cs.hmc.edu/twiki/bin/view/cs5/lab1b on 3/20/2017 Hw 1, Part 2 (Lab): Functioning smoothly! Using built-in functions Copied from: https://www.cs.hmc.edu/twiki/bin/view/cs5/lab1b on 3/20/2017 First, try out some of Python's many built-in functions. These

More information

CHAPTER 2: Introduction to Python COMPUTER PROGRAMMING SKILLS

CHAPTER 2: Introduction to Python COMPUTER PROGRAMMING SKILLS CHAPTER 2: Introduction to Python COMPUTER PROGRAMMING SKILLS 1439-1440 1 Outline 1. Introduction 2. Why Python? 3. Compiler and Interpreter 4. The first program 5. Comments and Docstrings 6. Python Indentations

More information

Introducing Python Pandas

Introducing Python Pandas Introducing Python Pandas Based on CBSE Curriculum Class -11 By- Neha Tyagi PGT CS KV 5 Jaipur II Shift Jaipur Region Neha Tyagi, KV 5 Jaipur II Shift Introduction Pandas or Python Pandas is a library

More information

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

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 Relation Databases 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 Database System is basically a record keeping

More information

Downloaded from Chapter 2. Functions

Downloaded from   Chapter 2. Functions Chapter 2 Functions After studying this lesson, students will be able to: Understand and apply the concept of module programming Write functions Identify and invoke appropriate predefined functions Create

More information

Python in 10 (50) minutes

Python in 10 (50) minutes Python in 10 (50) minutes https://www.stavros.io/tutorials/python/ Python for Microcontrollers Getting started with MicroPython Donald Norris, McGrawHill (2017) Python is strongly typed (i.e. types are

More information

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

Introduction to: Computers & Programming: Review prior to 1 st Midterm Introduction to: Computers & Programming: Review prior to 1 st Midterm Adam Meyers New York University Summary Some Procedural Matters Summary of what you need to Know For the Test and To Go Further in

More information

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

Introduction to Computer Programming CSCI-UA 2. Review Midterm Exam 1 Review Midterm Exam 1 Review Midterm Exam 1 Exam on Monday, October 7 Data Types and Variables = Data Types and Variables Basic Data Types Integers Floating Point Numbers Strings Data Types and Variables

More information

CSC326 Python Imperative Core (Lec 2)

CSC326 Python Imperative Core (Lec 2) i CSC326 Python Imperative Core (Lec ii REVISION HISTORY NUMBER DATE DESCRIPTION NAME 1.0 2011-09 JZ iii Contents 1 Agenda 1 2 Invoking Python 1 3 Value, Type, Variable 1 4 Keywords 2 5 Statement 2 6 Expression

More information

Unit E Step-by-Step: Programming with Python

Unit E Step-by-Step: Programming with Python Unit E Step-by-Step: Programming with Python Computer Concepts 2016 ENHANCED EDITION 1 Unit Contents Section A: Hello World! Python Style Section B: The Wacky Word Game Section C: Build Your Own Calculator

More information

Lab 4 Fruitful Functions

Lab 4 Fruitful Functions Lab 4 Fruitful Functions September 19, 2018 1 ME 30 Lab 4 - Functions and Style Description and Summary: >A function in programming is a block of code that performs some task. Functions are a way to organize

More information

Computer System Overview

Computer System Overview Computer System Overview based on CBSE curriculum Class 11 By- Neha Tyagi PGT CS KV 5 Jaipur II Shift, Jaipur Region Neha Tyagi, KV 5 Jaipur II Shift Introduction Computer is a machine which brought resolution

More information

by Pearson Education, Inc. All Rights Reserved. 2

by Pearson Education, Inc. All Rights Reserved. 2 Suppose you want to drive a car and make it go faster by pressing down on its accelerator pedal. Before you can drive a car, someone has to design it and build it. A car typically begins as engineering

More information

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

Fun with functions! Built-in and user-defined functions Fun with functions! A function is a block of code that performs a single action that can be reused indefinitely. They provide a great way of breaking code into smaller reusable pieces. And they're fun!

More information

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

Here n is a variable name. The value of that variable is 176. UNIT II DATA, EXPRESSIONS, STATEMENTS 9 Python interpreter and interactive mode; values and types: int, float, boolean, string, and list; variables, expressions, statements, tuple assignment, precedence

More information

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

What is a function? The Practice of Computing Using Python, Punch & Enbody, Copyright 2013 Pearson Education, Inc. Functions Husni What is a function? "The Practice of Computing Using Python", Punch & Enbody, Copyright 2013 Pearson Education, Inc. Functions From Mathematics we know that functions perform some operation

More information

7. C++ Class and Object

7. C++ Class and Object 7. C++ Class and Object 7.1 Class: The classes are the most important feature of C++ that leads to Object Oriented programming. Class is a user defined data type, which holds its own data members and member

More information

Ch.3: Functions and branching

Ch.3: Functions and branching Ch.3: Functions and branching Ole Christian Lingjærde, Dept of Informatics, UiO September 3-7, 2018 (PART 1) Today s agenda A small quiz to test understanding of lists Live-programming of exercises 2.7,

More information

Module 10: Imperative Programming, Modularization, and The Future

Module 10: Imperative Programming, Modularization, and The Future Module 10: Imperative Programming, Modularization, and The Future If you have not already, make sure you Read How to Design Programs Sections 18. 1 CS 115 Module 10: Imperative Programming, Modularization,

More information

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

The design recipe. Readings: HtDP, sections 1-5. (ordering of topics is different in lectures, different examples will be used) The design recipe Readings: HtDP, sections 1-5 (ordering of topics is different in lectures, different examples will be used) Survival and Style Guides CS 135 Winter 2018 02: The design recipe 1 Programs

More information

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

Exam 1 Format, Concepts, What you should be able to do, and Sample Problems CSSE 120 Introduction to Software Development Exam 1 Format, Concepts, What you should be able to do, and Sample Problems Page 1 of 6 Format: The exam will have two sections: Part 1: Paper-and-Pencil o

More information

Basics of Object Oriented Programming. Visit for more.

Basics of Object Oriented Programming. Visit   for more. Chapter 4: Basics of Object Oriented Programming Informatics Practices Class XII (CBSE Board) Revised as per CBSE Curriculum 2015 Visit www.ip4you.blogspot.com for more. Authored By:- Rajesh Kumar Mishra,

More information

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

Functions!!! Why functions? Functions provide good way to design systems! Functions!!! Why functions? Functions provide good way to design systems! Coding Design! DRY principle - Don't Repeat Yourself! Loops help with this! Functions/procedures/modules help even more! Modular

More information

Ch.3: Functions and branching

Ch.3: Functions and branching Ch.3: Functions and branching Ole Christian Lingjærde, Dept of Informatics, UiO September 4-8, 2017 Today s agenda A small quiz to test understanding of lists Live-programming of exercises 2.7, 2.14, 2.15

More information

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

COMP1730/COMP6730 Programming for Scientists. Data: Values, types and expressions. COMP1730/COMP6730 Programming for Scientists Data: Values, types and expressions. Lecture outline * Data and data types. * Expressions: computing values. * Variables: remembering values. What is data?

More information

JAVA GUI PROGRAMMING REVISION TOUR III

JAVA GUI PROGRAMMING REVISION TOUR III 1. In java, methods reside in. (a) Function (b) Library (c) Classes (d) Object JAVA GUI PROGRAMMING REVISION TOUR III 2. The number and type of arguments of a method are known as. (a) Parameter list (b)

More information

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

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

More information

Built-in Types of Data

Built-in Types of Data Built-in Types of Data Types A data type is set of values and a set of operations defined on those values Python supports several built-in data types: int (for integers), float (for floating-point numbers),

More information

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

A A B U n i v e r s i t y A A B U n i v e r s i t y Faculty of Computer Sciences O b j e c t O r i e n t e d P r o g r a m m i n g Week 4: Introduction to Classes and Objects Asst. Prof. Dr. M entor Hamiti mentor.hamiti@universitetiaab.com

More information

Python Workshop. January 18, Chaitanya Talnikar. Saket Choudhary

Python Workshop. January 18, Chaitanya Talnikar. Saket Choudhary Chaitanya Talnikar Saket Choudhary January 18, 2012 Python Named after this : Python Slide 1 was a joke! Python Slide 1 was a joke! Python : Conceived in late 1980s by Guido van Rossum as a successor to

More information

ChAmElEoN Parse Tree

ChAmElEoN Parse Tree ChAmElEoN Parse Tree Jack L. Watkin May 9, 2017 The objective of this appendix is to describe the abstract syntax tree (ast) generated by the ChAmElEoN parser. 1 Tree Node The ChAmElEoNparser builds an

More information

FUNCTION PARAMETER AND ARGUMENT

FUNCTION PARAMETER AND ARGUMENT FUNCTION PARAMETER AND ARGUMENT P.POOVIZHI AP-IT SNSCE 1 FRAME THE DEFINITION?? 2 DEFINITION OF FUNCTION A function is a block of organized, reusable code that is used to perform a single, related action.

More information

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

7/8/10 KEY CONCEPTS. Problem COMP 10 EXPLORING COMPUTER SCIENCE. Algorithm. Lecture 2 Variables, Types, and Programs. Program PROBLEM SOLVING KEY CONCEPTS COMP 10 EXPLORING COMPUTER SCIENCE Lecture 2 Variables, Types, and Programs Problem Definition of task to be performed (by a computer) Algorithm A particular sequence of steps that will solve

More information

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

Defining Functions. turning expressions into functions. writing a function definition defining and using modules Defining Functions 1 Lambda Functions turning expressions into functions 2 Functions and Modules writing a function definition defining and using modules 3 Computing Series Developments exploring an example

More information

Python 1: Intro! Max Dougherty Andrew Schmitt

Python 1: Intro! Max Dougherty Andrew Schmitt Python 1: Intro! Max Dougherty Andrew Schmitt Computational Thinking Two factors of programming: The conceptual solution to a problem. Solution syntax in a programming language BJC tries to isolate and

More information

Introduction to Python

Introduction to Python Introduction to Python EECS 4415 Big Data Systems Tilemachos Pechlivanoglou tipech@eecs.yorku.ca 2 Background Why Python? "Scripting language" Very easy to learn Interactive front-end for C/C++ code Object-oriented

More information

Babes-Bolyai University

Babes-Bolyai University Babes-Bolyai University arthur@cs.ubbcluj.ro Overview 1 Modules programming - a software design technique that increases the extent to which software is composed of independent, interchangeable components

More information

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

Introduction to: Computers & Programming Defining Identifiers: Objects with Names Introduction to: Computers & Programming Defining Identifiers: Objects with Names Adam Meyers New York University Outline The types of objects with names Functions, Variables, Programs, Modules, etc. Defining

More information

Python Day 3 11/28/16

Python Day 3 11/28/16 Python Day 3 11/28/16 Objectives Review Concepts Types of Errors Escape sequences String functions Find the Errors bookcost = int(input("how much is the book: ")) discount = float(input("what is the discount:

More information

Java Bytecode (binary file)

Java Bytecode (binary file) Java is Compiled Unlike Python, which is an interpreted langauge, Java code is compiled. In Java, a compiler reads in a Java source file (the code that we write), and it translates that code into bytecode.

More information

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

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

More information

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

Getting Started. Office Hours. CSE 231, Rich Enbody. After class By appointment send an  . Michigan State University CSE 231, Fall 2013 CSE 231, Rich Enbody Office Hours After class By appointment send an email 2 1 Project 1 Python arithmetic Do with pencil, paper and calculator first Idle Handin Help room 3 What is a Computer Program?

More information

Lecture 4. Defining Functions

Lecture 4. Defining Functions Lecture 4 Defining Functions Academic Integrity Quiz Reading quiz about the course AI policy Go to http://www.cs.cornell.edu/courses/cs11110/ Click Academic Integrity in side bar Read and take quiz in

More information

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

Overview. - General Data Types - Categories of Words. - Define Before Use. - The Three S s. - End of Statement - My First Program Overview - General Data Types - Categories of Words - The Three S s - Define Before Use - End of Statement - My First Program a description of data, defining a set of valid values and operations List of

More information

Introduction to Python Programming

Introduction to Python Programming advances IN SYSTEMS AND SYNTHETIC BIOLOGY 2018 Anna Matuszyńska Oliver Ebenhöh oliver.ebenhoeh@hhu.de Ovidiu Popa ovidiu.popa@hhu.de Our goal Learning outcomes You are familiar with simple mathematical

More information

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

Chapter 10. Class & Objects in JAVA. By: Deepak Bhinde PGT Com.Sc. Chapter 10 Class & Objects in JAVA By: Deepak Bhinde PGT Com.Sc. Objective In this presentation you will learn about the classes and objects which leads to Object Oriented Programming (OOP) in tha JAVA.

More information

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

More Data Types. The Char Data Type. Variable Declaration. CS200: Computer Science I. Module 14 More Data Types datatype CS200: Computer Science I Module 14 More Data Types Kevin Sahr, PhD Department of Computer Science Southern Oregon University 1 More Data Types in addition to the data types double and int we

More information

Module 01: Introduction to Programming in Python

Module 01: Introduction to Programming in Python Module 01: Introduction to Programming in Python Topics: Course Introduction Introduction to Python basics Readings: ThinkP 1,2,3 1 Finding course information https://www.student.cs.uwaterloo.ca/~cs116/

More information

Scripting Languages. Python basics

Scripting Languages. Python basics Scripting Languages Python basics Interpreter Session: python Direct conversation with python (>>>) Python 3.5.2 (default, Nov 23 2017, 16:37:01) [GCC 5.4.0 20160609] on linux Type "help", "copyright",

More information

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

Python allows variables to hold string values, just like any other type (Boolean, int, float). So, the following assignment statements are valid: 1 STRINGS Objectives: How text data is internally represented as a string Accessing individual characters by a positive or negative index String slices Operations on strings: concatenation, comparison,

More information

Accelerating Information Technology Innovation

Accelerating Information Technology Innovation Accelerating Information Technology Innovation http://aiti.mit.edu Cali, Colombia Summer 2012 Lesson 1 Introduction to Python Agenda What is Python? and Why Python? Basic Syntax Strings User Input Useful

More information

Chapter 8: Creating Your Own Type Classes

Chapter 8: Creating Your Own Type Classes Chapter 8: Creating Your Own Type Classes What we will learn: Object-oriented programming What is a class How to create a class Assigning values to a class What you need to know before: Data types Methods

More information

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

There are four numeric types: 1. Integers, represented as a 32 bit (or longer) quantity. Digits sequences (possibly) signed are integer literals: Numeric Types There are four numeric types: 1. Integers, represented as a 32 bit (or longer) quantity. Digits sequences (possibly) signed are integer literals: 1-123 +456 2. Long integers, of unlimited

More information

Lecture 17: Classes (Chapter 15)

Lecture 17: Classes (Chapter 15) http://www.cs.cornell.edu/courses/cs1110/2018sp Lecture 17: Classes (Chapter 15) CS 1110 Introduction to Computing Using Python [E. Andersen, A. Bracy, D. Gries, L. Lee, S. Marschner, C. Van Loan, W. White]

More information

Functions with Parameters and Return Values

Functions with Parameters and Return Values CS101, Spring 2015 Functions with Parameters and Return Values Lecture #4 Last week we covered Objects and Types Variables Methods Tuples Roadmap Last week we covered Objects and Types Variables Methods

More information

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

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #34. Function with pointer Argument Introduction to Programming in C Department of Computer Science and Engineering Lecture No. #34 Function with pointer Argument (Refer Slide Time: 00:05) So, here is the stuff that we have seen about pointers.

More information

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

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

More information

COMP1730/COMP6730 Programming for Scientists. Functions

COMP1730/COMP6730 Programming for Scientists. Functions COMP1730/COMP6730 Programming for Scientists Functions Lecture outline * Function definition. * Function calls & order of evaluation. * Assignments in functions; local variables. * Function testing. Functions

More information

Lecture 8: Euler s Methods

Lecture 8: Euler s Methods Lecture 8: Euler s Methods Forward Euler Method The formula for the forward Euler method is given by equation (8.2) in the lecture note for week 8, as y i+1 = y i + f(x i, y i )h. (1) where f(x i, y i

More information

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

Python I. Some material adapted from Upenn cmpe391 slides and other sources Python I Some material adapted from Upenn cmpe391 slides and other sources Overview Names & Assignment Data types Sequences types: Lists, Tuples, and Strings Mutability Understanding Reference Semantics

More information

Fundamentals of Programming Session 25

Fundamentals of Programming Session 25 Fundamentals of Programming Session 25 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2014 These slides have been created using Deitel s slides Sharif University of Technology Outlines

More information

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

7. (2 pts) str( str( b ) ) str '4' will not compile (single, double, or triple quotes For the following questions, use these variable definitions a = 45 b = 4 c = 39999 d = "7" What is the value and type of each of the following expressions or, if it won't compile, circle that answer type

More information

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

Step by step set of instructions to accomplish a task or solve a problem Step by step set of instructions to accomplish a task or solve a problem Algorithm to sum a list of numbers: Start a Sum at 0 For each number in the list: Add the current sum to the next number Make the

More information

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

The L Line. The Express Line to Learning. Wiley Publishing All Rights Reserved. L The L Line The Express Line to Learning Wiley Publishing. 2007. All Rights Reserved. 3 Taking Control Stations Along the Way Using the if statement Creating a condition Using else to work with false

More information

Introduction to computers and Python. Matthieu Choplin

Introduction to computers and Python. Matthieu Choplin Introduction to computers and Python Matthieu Choplin matthieu.choplin@city.ac.uk http://moodle.city.ac.uk/ 1 Objectives To get a brief overview of what Python is To understand computer basics and programs

More information

CS1 Lecture 3 Jan. 18, 2019

CS1 Lecture 3 Jan. 18, 2019 CS1 Lecture 3 Jan. 18, 2019 Office hours for Prof. Cremer and for TAs have been posted. Locations will change check class website regularly First homework assignment will be available Monday evening, due

More information

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

Java Methods. Lecture 8 COP 3252 Summer May 23, 2017 Java Methods Lecture 8 COP 3252 Summer 2017 May 23, 2017 Java Methods In Java, the word method refers to the same kind of thing that the word function is used for in other languages. Specifically, a method

More information

Python for C programmers

Python for C programmers Python for C programmers The basics of Python are fairly simple to learn, if you already know how another structured language (like C) works. So we will walk through these basics here. This is only intended

More information

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

THE AUSTRALIAN NATIONAL UNIVERSITY Mid Semester Examination September COMP1730 / COMP6730 Programming for Scientists THE AUSTRALIAN NATIONAL UNIVERSITY Mid Semester Examination September 2016 COMP1730 / COMP6730 Programming for Scientists Study Period: 15 minutes Time Allowed: 2 hours Permitted Materials: One A4 page

More information

Accelerating Information Technology Innovation

Accelerating Information Technology Innovation Accelerating Information Technology Innovation http://aiti.mit.edu/program/philippines-summer-2012/ Philippines Summer 2012 Lecture 1 Introduction to Python June 19, 2012 Agenda About the Course What is

More information

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

06/11/2014. Subjects. CS Applied Robotics Lab Gerardo Carmona :: makeroboticsprojects.com June / ) Beginning with Python CS95003 - Applied Robotics Lab Gerardo Carmona :: makeroboticsprojects.com June / 2014 Subjects 1) Beginning with Python 2) Variables 3) Strings 4) Basic arithmetic operators 5) Flow control 6) Comparison

More information

4. Modules and Functions

4. Modules and Functions 4. Modules and Functions The Usual Idea of a Function Topics Modules Using import Using functions from math A first look at defining functions sqrt 9 3 A factory that has inputs and builds outputs. Why

More information

CS1 Lecture 3 Jan. 22, 2018

CS1 Lecture 3 Jan. 22, 2018 CS1 Lecture 3 Jan. 22, 2018 Office hours for me and for TAs have been posted, locations will change check class website regularly First homework available, due Mon., 9:00am. Discussion sections tomorrow

More information

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

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 Week 9: Methods 1 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 long and hard to read Sometimes you

More information

Lecture 1. basic Python programs, defining functions

Lecture 1. basic Python programs, defining functions Lecture 1 basic Python programs, defining functions Lecture notes modified from CS Washington CS 142 Except where otherwise noted, this work is licensed under: http://creativecommons.org/licenses/by-nc-sa/3.0

More information

Key Differences Between Python and Java

Key Differences Between Python and Java Python Python supports many (but not all) aspects of object-oriented programming; but it is possible to write a Python program without making any use of OO concepts. Python is designed to be used interpretively.

More information

An Introduction to Python for KS4!

An Introduction to Python for KS4! An Introduction to Python for KS4 Python is a modern, typed language - quick to create programs and easily scalable from small, simple programs to those as complex as GoogleApps. IDLE is the editor that

More information

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

ENCM 339 Fall 2017 Lecture Section 01 Lab 9 for the Week of November 20 page 1 of 9 ENCM 339 Fall 2017 Lecture Section 01 Lab 9 for the Week of November 20 Steve Norman Department of Electrical & Computer Engineering University of Calgary November 2017 Lab instructions and

More information

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

PYTHON. Varun Jain & Senior Software Engineer. Pratap, Mysore Narasimha Raju & TEST AUTOMATION ARCHITECT. CenturyLink Technologies India PVT LTD PYTHON Varun Jain & Senior Software Engineer Pratap, Mysore Narasimha Raju & TEST AUTOMATION ARCHITECT CenturyLink Technologies India PVT LTD 1 About Python Python is a general-purpose interpreted, interactive,

More information

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

Programming in C. main. Level 2. Level 2 Level 2. Level 3 Level 3 Programming in C main Level 2 Level 2 Level 2 Level 3 Level 3 1 Programmer-Defined Functions Modularize with building blocks of programs Divide and Conquer Construct a program from smaller pieces or components

More information

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

Objects and Classes. 1 Creating Classes and Objects. CSCI-UA 101 Objects and Classes Based on Introduction to Java Programming, Y. Daniel Liang, Brief Version, 10/E 1 Creating Classes and Objects Classes give us a way of defining custom data types and associating data with operations on

More information

Lecture 02, Fall 2018 Friday September 7

Lecture 02, Fall 2018 Friday September 7 Anatomy of a class Oliver W. Layton CS231: Data Structures and Algorithms Lecture 02, Fall 2018 Friday September 7 Follow-up Python is also cross-platform. What s the advantage of Java? It s true: Python

More information

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

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming Intro to Programming Unit 7 Intro to Programming 1 What is Programming? 1. Programming Languages 2. Markup vs. Programming 1. Introduction 2. Print Statement 3. Strings 4. Types and Values 5. Math Externals

More information

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

Lecture 4: Defining Functions (Ch ) CS 1110 Introduction to Computing Using Python http://www.cs.cornell.edu/courses/cs0/209sp Lecture 4: Defining Functions (Ch..4-.) CS 0 Introduction to Computing Using Python [E. Andersen, A. Bracy, D. Gries, L. Lee, S. Marschner, C. Van Loan, W. White]

More information

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

Review Sheet for Midterm #1 COMPSCI 119 Professor William T. Verts Review Sheet for Midterm #1 COMPSCI 119 Professor William T. Verts Simple Data Types There are a number of data types that are considered primitive in that they contain only a single value. These data

More information

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

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines. Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

More information

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

Statements 2. a operator= b a = a operator b Statements 2 Outline Note: i=i+1 is a valid statement. Don t confuse it with an equation i==i+1 which is always false for normal numbers. The statement i=i+1 is a very common idiom: it just increments

More information

SOFT 161. Class Meeting 1.6

SOFT 161. Class Meeting 1.6 University of Nebraska Lincoln Class Meeting 1.6 Slide 1/13 Overview of A general purpose programming language Created by Guido van Rossum Overarching design goal was orthogonality Automatic memory management

More information