Browse Course Material

Course info, instructors.

  • Dr. Ana Bell
  • Prof. Eric Grimson
  • Prof. John Guttag

Departments

  • Electrical Engineering and Computer Science

As Taught In

  • Algorithms and Data Structures
  • Programming Languages

Learning Resource Types

Introduction to computer science and programming in python, lecture slides and code.

The slides and code from each lecture are available below.

facebook

You are leaving MIT OpenCourseWare

  • Chapter 3: Branch
  • Chapter 4: Loop
  • Chapter 5: Function
  • Chapter 6 Collection

Presentation Slides ¶

Part i. fundamental python programming ¶, chapter 1: introduction to programming ¶.

  • Python Crash Course

Chapter 2: Variable and Expression ¶

  • Variables .
  • Expression and Statements
  • Turtle Introduction

Chapter 3 Branch ¶

Chapter 4 loop ¶, chapter 5 function ¶, chapter 6 collection ¶, chapter 7 class ¶.

  • Basic Class
  • Advanced Class

Part II. Advanced Programming ¶

Chapter 8 exception ¶, chapter 9 module ¶, chapter 10 file ¶, chapter 11 python data model ¶, part iii. algorithmic thinking ¶, chapter 12 a web site ¶.

  • Django Crash Course
  • Basic Django
  • Advanced Django
  • Top Courses
  • Online Degrees
  • Find your New Career
  • Join for Free

University of Pennsylvania

Introduction to Python Programming

This course is part of Introduction to Programming with Python and Java Specialization

Taught in English

Some content may not be translated

Brandon Krakowsky

Instructor: Brandon Krakowsky

Financial aid available

76,720 already enrolled

Coursera Plus

(1,052 reviews)

Recommended experience

Beginner level

High school or college math.

Minimal prior programming exposure may be helpful but not needed (e.g. Computational Thinking for Problem Solving ).

What you'll learn

Identify core aspects of programming and features of the Python language

Understand and apply core programming concepts like data structures, conditionals, loops, variables, and functions

Use different tools for writing and running Python code

Design and write fully-functional Python programs using commonly used data structures, custom functions, and reading and writing to files

Skills you'll gain

  • Programming Principles
  • Python Syntax And Semantics
  • Computer Programming
  • Python Programming
  • Python Tools

Details to know

presentation on python programming

Add to your LinkedIn profile

See how employees at top companies are mastering in-demand skills

Placeholder

Build your subject-matter expertise

  • Learn new concepts from industry experts
  • Gain a foundational understanding of a subject or tool
  • Develop job-relevant skills with hands-on projects
  • Earn a shareable career certificate

Placeholder

Earn a career certificate

Add this credential to your LinkedIn profile, resume, or CV

Share it on social media and in your performance review

Placeholder

There are 4 modules in this course

This course provides an introduction to programming and the Python language. Students are introduced to core programming concepts like data structures, conditionals, loops, variables, and functions. This course includes an overview of the various tools available for writing and running Python, and gets students coding quickly. It also provides hands-on coding exercises using commonly used data structures, writing custom functions, and reading and writing to files. This course may be more robust than some other introductory python courses, as it delves deeper into certain essential programming topics.

Module 1 : Course Introduction, Intro to Programming and The Python Language, Variables, Conditionals, Jupyter Notebook, and IDLE

This first module covers an intro to programming and the Python language. We’ll start by downloading and installing the necessary tools to begin programming and writing code in Python. After learning how to print to the console, we’ll get an understanding of Python’s basic data types, and how to do simple math. We’ll follow up by creating our first Python script, and learn how to define and assign variables, while controlling the flow of our program using conditionals. We’ll also learn how to get input from the user, including some very basic error checking. Let’s get started!

What's included

42 videos 10 readings 3 quizzes 2 programming assignments

42 videos • Total 78 minutes

  • About the Instructor : Brandon Krakowsky • 1 minute • Preview module
  • What you should expect from this Course • 1 minute
  • Why begin with Python? • 0 minutes
  • Module Intro • 0 minutes
  • What is Programming? • 0 minutes
  • Client-side vs. server-side programming • 0 minutes
  • Introduction to core programming concepts: Data structures, Conditionals, Variables, Functions, and Loops • 1 minute
  • What is Python? • 0 minutes
  • Python is interpreted • 0 minutes
  • Why Python? • 0 minutes
  • Downloading & installing Python • 0 minutes
  • Downloading & Installing Jupyter Notebook • 0 minutes
  • Using Jupyter Notebook • 3 minutes
  • How do I write Python? • 0 minutes
  • Printing • 2 minutes
  • Basic Data Types • 2 minutes
  • Arithmetic operators • 1 minute
  • About division • 1 minute
  • Boolean values • 1 minute
  • Comparison operators • 0 minutes
  • Code Along Exercise : Even/Odd • 0 minutes
  • Strings • 2 minutes
  • Casting • 3 minutes
  • How to use Coursera Labs & understand Autograder output • 9 minutes
  • Downloading & installing IDLE • 0 minutes
  • Using the IDLE shell • 1 minute
  • Running a Python script • 1 minute
  • Adding comments to Python scripts • 1 minute
  • Code Along Exercise : Comment the program to greet user • 1 minute
  • Assigning a variable • 0 minutes
  • Boolean operators • 1 minute
  • Variable substitution • 2 minutes
  • Combining variables • 1 minute
  • Code Along Exercise : Cats & dogs • 1 minute
  • Getting user input • 3 minutes
  • Code Along Exercise : Calculate total bill • 6 minutes
  • The if … elif … else statement • 2 minutes
  • Code Along Exercise : Numerical grade to letter grade • 2 minutes
  • Multiple if conditionals • 1 minute
  • Checking user input • 1 minute
  • Coding Demonstration : Common Python Errors • 6 minutes
  • Coding Demonstration : Creating a function to convert numerical grade to letter grade • 3 minutes

10 readings • Total 100 minutes

  • Course Layout & Syllabus • 15 minutes
  • Tips to succeed in this course • 10 minutes
  • Module 1 Resources (DOWNLOAD RELEVANT CODE AND/OR DATA FILES FOR THIS MODULE HERE) • 30 minutes
  • Python - Getting Help • 2 minutes
  • Quick Intro to Variables • 5 minutes
  • Homework 1a : Instructions • 10 minutes
  • What is a Python script? • 3 minutes
  • Python Errors • 10 minutes
  • Reading : Quick Intro to Functions • 5 minutes
  • Homework 1b : Instructions • 10 minutes

3 quizzes • Total 60 minutes

  • Practice Quiz - Variables & data types • 30 minutes
  • Quiz 1 - Intro to Python & The Python Language • 10 minutes
  • Quiz 2 - Variables & Conditionals • 20 minutes

2 programming assignments • Total 270 minutes

  • Homework 1a - Math Practice • 120 minutes
  • Homework 1b - Practice Writing Python & Calculating How Old Your Dog is in Human Years • 150 minutes

Module 2 : Intro to Lists, Loops, and Functions

We’ll start this module with a brief intro to lists, one of Python’s most commonly used data structures. We’ll learn just enough to get us started with loops, which are used to repeat a process or run a block of code multiple times. We’ll get into functions, which are blocks of organized code used to perform a single, related action. We’ll review some of Python’s built-in functions and learn how to design our own user-defined functions to use as building blocks in our own programs. Along the way, we’ll learn best practices for documenting our code for 2 different audiences: The users who are using our code and want to understand it at a high level, and the programmers who are reading it and want to know how it works.

31 videos 2 readings 3 quizzes 1 programming assignment

31 videos • Total 56 minutes

  • Module Introduction • 1 minute • Preview module
  • Creating a list • 0 minutes
  • Updating a list • 1 minute
  • Types of Loops • 0 minutes
  • Executing code a given number of times • 1 minute
  • Iterating over a list • 3 minutes
  • Code Along Exercise : Find minimum value • 2 minutes
  • Iterating over strings • 1 minute
  • Iterate over a string • 1 minute
  • Code Along Exercise : Iterate over a name • 1 minute
  • 'for' loops using range • 4 minutes
  • Repeatedly executing code based on a condition • 1 minute
  • Waiting for user input • 0 minutes
  • Code Along Exercise : Secret password • 1 minute
  • Exiting a loop using break • 1 minute
  • Exiting a loop using continue • 1 minute
  • Nested loops • 1 minute
  • Code Along Exercise : Multiplication tables • 1 minute
  • Coding Demonstration : Average program • 4 minutes
  • Coding Demonstration : Word reversal • 1 minute
  • What is a function? • 0 minutes
  • Built-in functions • 0 minutes
  • User-defined functions • 0 minutes
  • Code Along Exercise : Square • 0 minutes
  • Code Along Exercise : Greater than • 1 minute
  • Docstrings (Documentation Strings) • 0 minutes
  • Code Along Exercise : Get factors • 2 minutes
  • Code Along Exercise : Unique list • 2 minutes
  • Execution order • 0 minutes
  • The main function • 0 minutes
  • Coding Demonstration : Vowel/word counter • 9 minutes

2 readings • Total 40 minutes

  • Module 2 Resources (DOWNLOAD RELEVANT CODE AND/OR DATA FILES FOR THIS MODULE HERE) • 30 minutes
  • Homework 2 : Instructions • 10 minutes

3 quizzes • Total 58 minutes

  • Practice Quiz : Intro to Lists, Loops, and Functions • 30 minutes
  • Quiz 3 - Intro to Lists & Loops • 18 minutes
  • Quiz 4 - Functions • 10 minutes

1 programming assignment • Total 240 minutes

  • Homework 2 - Number Properties • 240 minutes

Module 3 : More with Lists, Strings, Tuples, Sets, and PyCharm

In this module, we’re going to start using PyCharm, another IDE for writing and running Python code. It has enhanced features that go way beyond the limited functionality of IDLE, and it’s also an industry standard. After revisiting lists, including more advanced usage of the commonly used sequence, we’ll take a deep dive into two other very important data structures : sets and tuples. We’ll learn how they can be leveraged to both store and manipulate information. And while we already have some experience working with strings, this module will explore the intricacies and more powerful functionality of strings.

16 videos 3 readings 3 quizzes 1 programming assignment

16 videos • Total 25 minutes

  • Module introduction • 0 minutes • Preview module
  • About PyCharm • 0 minutes
  • Downloading & installing PyCharm • 0 minutes
  • Running code • 1 minute
  • A review of lists • 2 minutes
  • More list operations • 0 minutes
  • List functions • 0 minutes
  • Slicing lists • 6 minutes
  • Strings vs. lists • 0 minutes
  • Slicing strings • 1 minute
  • Code Along Exercise : Name Substring • 1 minute
  • Split and join • 1 minute
  • Creating a tuple • 1 minute
  • Code Along Exercise : Max and min function • 4 minutes
  • Creating a set • 1 minute
  • Iterating over and updating a set • 0 minutes

3 readings • Total 45 minutes

  • Module 3 Resources (DOWNLOAD RELEVANT CODE AND/OR DATA FILES FOR THIS MODULE HERE) • 30 minutes
  • String functions • 5 minutes
  • Homework 3 : Instructions • 10 minutes

3 quizzes • Total 50 minutes

  • Practice Quiz : Jupyter Notebook, IDLE, & PyCharm • 30 minutes
  • Quiz 5 - Lists & Strings • 10 minutes
  • Quiz 6 - Tuples & Sets • 10 minutes
  • Homework 3 - Implement Functions Related to Strings, Lists, Sets, & Tuples • 240 minutes

Module 4 : Dictionaries and Files

There are multiple ways of loading and storing data in Python. Information can be saved in dictionaries, a data structure that is extremely useful for storing multiple attributes (or data points) about a single thing. Data can also be stored in external files and then loaded into Python. This module will allow us to work with dictionaries in a variety of ways and to interact with the local file system by opening, reading from, and writing to, external files. With these added skills, you’ll begin to get a better sense of the dynamic power of Python and how it can be easily integrated with other systems.

17 videos 2 readings 3 quizzes 1 programming assignment

17 videos • Total 54 minutes

  • Module Introduction • 0 minutes • Preview module
  • Creating a dictionary • 0 minutes
  • Key:value pairs • 0 minutes
  • Updating a dictionary • 0 minutes
  • Code Along Exercise : Grade/attendance book • 9 minutes
  • Opening a file • 0 minutes
  • Basics of file open method modes • 1 minute
  • Reading a file • 0 minutes
  • Newline characters • 0 minutes
  • Writing to a file • 0 minutes
  • Closing a file • 0 minutes
  • Coding Demonstration : Open and read a file • 3 minutes
  • Coding Demonstration : Open, read, and append to new file • 3 minutes
  • Coding Demonstration : Open, read, and append to same file • 3 minutes
  • Coding Demonstration : Open, read, and write to new file • 2 minutes
  • Coding Demonstration : File to Dictionary • 11 minutes
  • Intro to Homework 4 • 13 minutes
  • Module 4 Resources (DOWNLOAD RELEVANT CODE AND/OR DATA FILES FOR THIS MODULE HERE) • 30 minutes
  • Homework 4 : Instructions • 10 minutes

3 quizzes • Total 56 minutes

  • Practice Quiz : Python Dictionaries & Files • 30 minutes
  • Quiz 7 - Dictionaries • 14 minutes
  • Quiz 8 - File I/O • 12 minutes
  • Homework 4 - Online Banking System • 240 minutes

Instructor ratings

We asked all learners to give feedback on our instructors based on the quality of their teaching style.

presentation on python programming

The University of Pennsylvania (commonly referred to as Penn) is a private university, located in Philadelphia, Pennsylvania, United States. A member of the Ivy League, Penn is the fourth-oldest institution of higher education in the United States, and considers itself to be the first university in the United States with both undergraduate and graduate studies.

Recommended if you're interested in Software Development

presentation on python programming

University of Pennsylvania

Introduction to Programming with Python and Java

Specialization

presentation on python programming

Data Analysis Using Python

presentation on python programming

Duke University

Python Programming Fundamentals

presentation on python programming

Coursera Project Network

Simple Parallel Coordinates Plot using d3 js

Guided Project

Why people choose Coursera for their career

presentation on python programming

Learner reviews

Showing 3 of 1052

1,052 reviews

Reviewed on Apr 14, 2024

I really enjoyed this course. It was well paced and covered the basics nicely. The practice exercises were hard, but made sure you learned all the key concepts.

Reviewed on Feb 9, 2022

The course content is well planned. Th assignments and discussion forums are outstanding. Would like to give 4.5/5 since I think the topics can be bit more explained thoroughly.

Reviewed on Feb 11, 2021

I can't wait to enroll for the 100% online master at Penn U. The instructor in this course has shown a great value of this introduction to python programming.

New to Software Development? Start here.

Placeholder

Open new doors with Coursera Plus

Unlimited access to 7,000+ world-class courses, hands-on projects, and job-ready certificate programs - all included in your subscription

Advance your career with an online degree

Earn a degree from world-class universities - 100% online

Join over 3,400 global companies that choose Coursera for Business

Upskill your employees to excel in the digital economy

Frequently asked questions

Do i need to know how to program or have studied computer science in order to take this course.

No, definitely not! This Specialization is intended for anyone who has an interest in problem solving and wants to learn introductory Python or Java. No prior computer science or programming experience is required.

How much math do I need to know to take this course?

The only math that learners will need for this Specialization is arithmetic and basic concepts in logic.

This course was fun. How can I learn more?

This course is the first in the Introduction to Programming with Python and Java Specialization. If you enjoyed it, we recommend Courses 2, 3 and 4 in the series!

If you would like to learn the fundamentals of computer science beyond the basics of programming, consider applying to the Master of Computer and Information and Technology (MCIT) at the University of Pennsylvania, an Ivy League computer science master’s program for people without a computer science background. For an on-campus experience, explore here Opens in a new tab . If you prefer an online setting, apply to MCIT Online Opens in a new tab . In fact, the lectures in this series are also used in the online degree program! The Specialization certificate will be viewed favorably by the admissions committee, so be sure to mention it when you apply.

When will I have access to the lectures and assignments?

Access to lectures and assignments depends on your type of enrollment. If you take a course in audit mode, you will be able to see most course materials for free. To access graded assignments and to earn a Certificate, you will need to purchase the Certificate experience, during or after your audit. If you don't see the audit option:

The course may not offer an audit option. You can try a Free Trial instead, or apply for Financial Aid.

The course may offer 'Full Course, No Certificate' instead. This option lets you see all course materials, submit required assessments, and get a final grade. This also means that you will not be able to purchase a Certificate experience.

What will I get if I subscribe to this Specialization?

When you enroll in the course, you get access to all of the courses in the Specialization, and you earn a certificate when you complete the work. Your electronic Certificate will be added to your Accomplishments page - from there, you can print your Certificate or add it to your LinkedIn profile. If you only want to read and view the course content, you can audit the course for free.

What is the refund policy?

If you subscribed, you get a 7-day free trial during which you can cancel at no penalty. After that, we don’t give refunds, but you can cancel your subscription at any time. See our full refund policy Opens in a new tab .

Is financial aid available?

Yes. In select learning programs, you can apply for financial aid or a scholarship if you can’t afford the enrollment fee. If fin aid or scholarship is available for your learning program selection, you’ll find a link to apply on the description page.

More questions

Python Tutorial

File handling, python modules, python numpy, python pandas, python matplotlib, python scipy, machine learning, python mysql, python mongodb, python reference, module reference, python how to, python examples, python introduction, what is python.

Python is a popular programming language. It was created by Guido van Rossum, and released in 1991.

It is used for:

  • web development (server-side),
  • software development,
  • mathematics,
  • system scripting.

What can Python do?

  • Python can be used on a server to create web applications.
  • Python can be used alongside software to create workflows.
  • Python can connect to database systems. It can also read and modify files.
  • Python can be used to handle big data and perform complex mathematics.
  • Python can be used for rapid prototyping, or for production-ready software development.

Why Python?

  • Python works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc).
  • Python has a simple syntax similar to the English language.
  • Python has syntax that allows developers to write programs with fewer lines than some other programming languages.
  • Python runs on an interpreter system, meaning that code can be executed as soon as it is written. This means that prototyping can be very quick.
  • Python can be treated in a procedural way, an object-oriented way or a functional way.

Good to know

  • The most recent major version of Python is Python 3, which we shall be using in this tutorial. However, Python 2, although not being updated with anything other than security updates, is still quite popular.
  • In this tutorial Python will be written in a text editor. It is possible to write Python in an Integrated Development Environment, such as Thonny, Pycharm, Netbeans or Eclipse which are particularly useful when managing larger collections of Python files.

Python Syntax compared to other programming languages

  • Python was designed for readability, and has some similarities to the English language with influence from mathematics.
  • Python uses new lines to complete a command, as opposed to other programming languages which often use semicolons or parentheses.
  • Python relies on indentation, using whitespace, to define scope; such as the scope of loops, functions and classes. Other programming languages often use curly-brackets for this purpose.

Get Certified

COLOR PICKER

colorpicker

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: [email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail: [email protected]

Top Tutorials

Top references, top examples, get certified.

an overview to the basics of python programming language

Basics of Python Programming

Jan 02, 2020

2.18k likes | 2.98k Views

An overview to the basics of python programming language. Basics of Python Programming. Origin of Python. Python is a general-purpose interpreted, interactive, object-oriented, and high-level programming language. It was created by Guido van Rossum during 1985- 1990.

Share Presentation

  • membership operators
  • interactive mode
  • python assignment operators
  • pep python enhancement proposals

dewittb

Presentation Transcript

An overview to the basics of python programming language Basics of Python Programming

Origin of Python • Python is a general-purpose interpreted, interactive, object-oriented, and high-level programming language. It was created by Guido van Rossum during 1985- 1990. • Python is designed to be highly readable. It uses English keywords frequently where as other languages use punctuation

Basic features • Easy-to-learn: Python has few keywords, simple structure, and a clearly defined syntax • Easy-to-read: Python code is more clearly defined and visible to the eyes • A broad standard library: Python's bulk of the library is very portable and cross-platform compatible on UNIX, Windows, and Macintosh • Interactive Mode: Python has support for an interactive mode

Basic features: Continued • Easy-to-maintain: Python's source code is fairly easy-to-maintain • Portable • Extendable: You can add low-level modules to the Python interpreter • Databases: Python provides interfaces to all major commercial databases • Scalable: Python provides a better structure and support for large programs than shell scripting

Basic features: Continued • IT supports functional and structured programming methods as well as OOP • It can be used as a scripting language or can be compiled to byte-code for building large applications • It provides very high-level dynamic data types and supports dynamic type checking • IT supports automatic garbage collection • It can be easily integrated with C, C++, COM, ActiveX, CORBA, and Java

PEP – Python Enhancement Proposals • 8 Style Guide for Python Code • 20 The Zen of Python • 257 Docstring Conventions • More than thousand proposals • Helps in imporving and evolving the language

Different modes of python programming • Interactive Mode Programming • Script Mode Programming

Python Identifiers • A Python identifier is a name used to identify a variable, function, class, module, or other object. An identifier starts with a letter A to Z or a to z, or an underscore (_) followed by zero or more letters, underscores and digits (0 to 9) • Python does not allow punctuation characters such as @, $, and % within identifiers. • Python is a case sensitive programming language

Naming conventions for python identifiers • Class names start with an uppercase letter. All other identifiers start with a lowercase letter. • Starting an identifier with a single leading underscore indicates that the identifier is private. • Starting an identifier with two leading underscores indicates a strongly private identifier. • If the identifier also ends with two trailing underscores, the identifier is a language-defined special name.

Python Keywords • These are reserved words and you cannot use them as constant or variable or any other identifier names • All the Python keywords contain lowercase letters only. • E.G : and, assert, try, for, if, lambda etc

All the python Keywords And, exec, Not Assert, finally, or Break, for, pass Class, from, print Continue, global, raise Def, if, return Del, import, try Elif, in, while Else, is, with Except, lambda, yield

Lines and Indentation • Python provides no braces to indicate blocks of code for class and function definitions or flow control • Blocks of code are denoted by line indentation, which is rigidly enforced. • The number of spaces in the indentation is variable, but all statements within the block must be indented the same amount • in Python all the continuous lines indented with same number of spaces would form a block

Quotation/Comments in Python • Python accepts single ('), double (") and triple (''' or """) quotes to denote string literals, as long as the same type of quote starts and ends the string • The triple quotes are used to span the string across multiple lines • word = 'word' • sentence = "This is a sentence." • paragraph = """This is a paragraph. It is made up of multiple lines and sentences.""" • Comments start with a #

Variable types • Variables are nothing but reserved memory locations to store values. • This means 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

Assigning Values to Variables • Python variables do not need explicit declaration to reserve memory space • The declaration happens automatically when you assign a value to a variable. • The equal sign (=) is used to assign values to variables. • The operand to the left of the = operator is the name of the variable and the operand to the right of the = operator is the value stored in the variable • counter = 100 • miles = 1000.0 • name = "antony"

Multiple Assignment • Python allows you to assign a single value to several variables simultaneously • a = b = c = 1 • Here, an integer object is created with the value 1, and all three variables are assigned to the same memory location. • You can also assign multiple objects to multiple variables. • a, b, c = 1, 2, "antony"

Standard Data Types Python has five standard data types • Numbers • String • List • Tuple • Dictionary

Python Numbers • Number data types store numeric values • Number objects are created when you assign a value to them Python supports four different numerical types • int (signed integers) • long (long integers, they can also be represented in octal and hexadecimal) • float (floating point real values) • complex (complex numbers)

Python Strings • Strings in Python are identified as a contiguous set of characters represented in the quotation marks • Python allows for either pairs of single or double quotes • Subsets • of strings can be taken using the slice operator ([ ] and [:] ) with indexes starting at 0 in the beginning of the string and working their way from -1 at the end • The plus (+) sign is the string concatenation operator and the asterisk (*) is the repetition operator.

Python Lists • Lists are the most versatile of Python's compound data types • A list contains items separated by commas and enclosed within square brackets ([]) • To some extent, lists are similar to arrays in C. One difference between them is that all the items belonging to a list can be of different data type. • The values stored in a list can be accessed using the slice operator ([ ] and [:]) with indexes starting at 0 in the beginning of the list and working their way to end -1 • The plus (+) sign is the list concatenation operator, and the asterisk (*) is the repetition operator.

Python Tuples • A tuple is another sequence data type that is similar to the list • A tuple consists of a number of values separated by commas. Unlike lists, however, tuples are enclosed within parentheses • The main differences between lists and tuples are: Lists are enclosed in brackets ( [] ) and their elements and size can be changed, while tuples are enclosed in parentheses ( ( ) ) and cannot be updated. Tuples can be thought of as readonly lists.

Python Dictionary • Python's dictionaries are kind of hash table type • They work like associative arrays or hashes and consist of key-value pairs. • A dictionary key can be almost any Python type, but are usually numbers or strings. Values, on the other hand, can be any arbitrary Python object. • Dictionaries are enclosed by curly braces ({ }) and values can be assigned and accessed using square braces ([])

BASIC OPERATORS Arithmetic Operators Comparison (Relational) Operators Assignment Operators Logical Operators Bitwise Operators Membership Operators Identity Operators

Python Arithmetic Operator + Addition a + b = 30 - Subtraction a – b = -10 * Multiplication a * b = 200 / Division b / a = 2 % Modulus b % a = 0 ** Exponent a**b =10 to the Power 20 // 9//2 = 4 and 9.0//2.0 = 4.0

Python Comparison Operators == If the values of two operands are equal, then the condition becomes true != If values of two operands are not equal, then condition becomes true. <> If values of two operands are not equal, then condition becomes true. > < >= <=

Python Assignment Operators = Assigns values from right side operands to left side operand += It adds right operand to the left operand and assign the result to left operand -= *= /= %= **= //=

Python Bitwise Operators & Binary AND | Binary OR ^ Binary XOR

Python Logical Operators And Or not

Python Membership Operators Python’s membership operators test for membership in a sequence, such as strings,lists, or tuples in not in

Python Identity Operators is Evaluates to true if the variables on either side of the operator point to the same object and false otherwise is not Evaluates to false if the variables on either side of the operator point to the same object and true otherwise.

DECISION MAKING 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. if statements

LOOPS In general, statements are executed sequentially: The first statement in a function is executed first, followed by the second, and so on. There may be a situation when you need to execute a block of code several number of times. Programming languages provide various control structures that allow for more complicated execution paths.

while loop Repeats a statement or group of statements while a given condition is TRUE. It tests the condition before executing the loop body. A while loop statement in Python programming language repeatedly executes a target statement as long as a given condition is true. count = 0 while (count < 9): print 'The count is:', count count = count + 1

Using else Statement with Loops Python supports to have an else statement associated with a loop statement.  If the else statement is used with a for loop, the else statement is executed when the loop has exhausted iterating the list.  If the else statement is used with a while loop, the else statement is executed when the condition becomes false

Loop Control Statements break statement - Terminates the loop statement and transfers execution to the statement immediately following the loop. continue statement - Causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating pass statement - The pass statement in Python is used when a statement is required syntactically but you do not want any command or code to execute.

DATE AND TIME A Python program can handle date and time in several ways. Converting between date formats is a common chore for computers. Python's time and calendar modules help track dates and times. There is a popular time module available in Python which provides functions for working with times and for converting between representations. The function time.time() returns the current system time in ticks since 12:00am, January 1, 1970

Defining a 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 or docstring.  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

CLASSES AND OBJECTS Class: A user-defined prototype for an object that defines a set of attributes that characterize any object of the class. The attributes are data members (class variables and instance variables) and methods, accessed via dot notation.  Class variable: A variable that is shared by all instances of a class. Class variables are defined within a class but outside any of the class's methods. Class variables are not used as frequently as instance variables are.  Data member: A class variable or instance variable that holds data associated with a class and its objects.  Function overloading: The assignment of more than one behavior to a particular function. The operation performed varies by the types of objects or arguments involved.  Instance variable: A variable that is defined inside a method and belongs only to the current instance of a class.  Inheritance: The transfer of the characteristics of a class to other classes that are derived from it.  Instance: An individual object of a certain class. An object obj that belongs to a class Circle, for example, is an instance of the class Circle.  Instantiation: The creation of an instance of a class.  Method: A special kind of function that is defined in a class definition

Creating Classes class Employee: 'Common base class for all employees' empCount = 0 def __init__(self, name, salary): self.name = name self.salary = salary Employee.empCount += 1 def displayCount(self): print "Total Employee %d" % Employee.empCount def displayEmployee(self): print "Name : ", self.name, ", Salary: ", self.salary

Destroying Objects (Garbage Collection) Python deletes unneeded objects (built-in types or class instances) automatically to free the memory space. The process by which Python periodically reclaims blocks of memory that no longer are in use is termed Garbage Collection.

File Handling file object = open(file_name [, access_mode][, buffering]) - file_name: The file_name argument is a string value that contains the name of the file that you want to access - access_mode: The access_mode determines the mode in which the file has to be opened. This is optional parameter and the default file access mode is read (r). - buffering: If the buffering value is set to 0, no buffering takes place. If the buffering value is 1, line buffering is performed while accessing a file. If you specify the buffering value as an integer greater than 1, then buffering action is performed with the indicated buffer size. If negative, the buffer size is the system default (default behavior).

Modes - r - Opens a file for reading only. The file pointer is placed at the beginning of the file. This is the default mode. - rb - Opens a file for reading only in binary format. The file pointer is placed at the beginning of the file. - r+ - Opens a file for both reading and writing. The file pointer is placed at the beginning of the file. - rb+ - Opens a file for both reading and writing in binary format. The file pointer is placed at the beginning of the file. - w - Opens a file for writing only. Overwrites the file if the file exists. If the file does not exist, creates a new file for writing.

Modes - wb - Opens a file for writing only in binary format. Overwrites the file if the file exists. If the file does not exist, creates a new file for writing. - w+ - Opens a file for both writing and reading. Overwrites the existing file if the file exists. If the file does not exist, creates a new file for reading and writing. - wb+ - Opens a file for both writing and reading in binary format. Overwrites the existing file if the file exists. If the file does not exist, creates a new file for reading and writing. - a - Opens a file for appending. The file pointer is at the end of the file if the file exists. That is, the file is in the append mode. If the file does not exist, it creates a new file for writing.

Modes - ab - Opens a file for appending in binary format. The file pointer is at the end of the file if the file exists. That is, the file is in the append mode. If the file does not exist, it creates a new file for writing. - a+ - Opens a file for both appending and reading. The file pointer is at the end of the file if the file exists. The file opens in the append mode. If the file does not exist, it creates a new file for reading and writing. - ab+ - Opens a file for both appending and reading in binary format. The file pointer is at the end of the file if the file exists. The file opens in the append mode. If the file does not exist, it creates a new file for reading and writing

File attributes - file.closed - Returns true if file is closed, false otherwise - file.mode - Returns access mode with which file was opened. - file.name - Returns name of the file. - file.softspace - Returns false if space explicitly required with print, true otherwise.

Example # Open a file fo = open("foo.txt", "wb") print "Name of the file: ", fo.name print "Closed or not : ", fo.closed print "Opening mode : ", fo.mode print "Softspace flag : ", fo.softspace

The close() Method The close() method of a file object flushes any unwritten information and closes the file object, after which no more writing can be done. Python automatically closes a file when the reference object of a file is reassigned to another file. It is a good practice to use the close() method to close a file. fileObject.close();

The write() Method - The write() method writes any string to an open file. It is important to note that Python strings can have binary data and not just text. - The write() method does not add a newline character ('\n') to the end of the string - fileObject.write(string); # Open a file fo = open("foo.txt", "wb") fo.write( "Python is a great language.\nYeah its great!!\n"); # Close opend file fo.close()

File positions # Check current position position = fo.tell(); print "Current file position : ", position # Reposition pointer at the beginning once again position = fo.seek(0, 0); str = fo.read(10); print "Again read String is : ", str # Close opend file fo.close()

  • More by User

Python Programming

Python Programming

Chapter 2: Variables, expressions, and statements. Python Programming. Saad Bani Mohammad Department of Computer Science Al al-Bayt University. 1 st 2011/2012. Values and Types. A value is one of the fundamental things - like a letter or a number - that a program manipulates.

610 views • 17 slides

Python Programming

Chapter 5: Fruitful Functions. Python Programming. Saad Bani Mohammad Department of Computer Science Al al-Bayt University. 1 st 2011/2012. Return Values.

404 views • 17 slides

Python Basics

Python Basics

Python Basics. Python History. Late 1970s: programming language called ABC at the Centrum voor Wiskunde en Informatica in the Netherlands Audience included physicists, social scientists, and linguists 1983: Guido van Rossum joined the ABC team

1.94k views • 18 slides

Python Basics

Python Basics. Tom LeFebvre. Python Language. Very High-Level Language Scripting Language (no compiling) Simple syntax Easy to Learn/Use Slow execution. Indentation. Python uses indentation to identify blocks of code Might be difficult to get used to Code is more readable.

434 views • 18 slides

Python Programming

Python Programming. Installing Python. We are going to use Jython . Install JES ( Jthon Environment for Students) JES: Like a text editor comes with a bunch of built-in stuff that you can use to work on images and sound files by writing small chunks of code. Installation.

583 views • 33 slides

Python Basics

Python Basics. Python History. Late 1970s: programming language called ABC at the Centrum voor Wiskunde en Informatica in the Netherlands Audience included physicists , social scientists , and linguists 1983: Guido van Rossum joined the ABC team

402 views • 18 slides

Python Programming

Python Programming. by Chris Seddon. Python Programming. 13. Exception Handling 14. Unit Test 15. Inheritance 16. Threading 17. Extending and Embedding 18. Meta Classes 19. cx_Oracle 20. Operator Overloading 21. Web Application Frameworks 22. JSON and XML

4.4k views • 337 slides

Python Programming

Python Programming. overview. by. Aliki Muradova. Technical University of Crete. Why Python?. What advantages has it?. Python Programming. The Reasons for Choosing Python. Python is free It is object-oriented It is interpreted It is operating-system independent

1.01k views • 30 slides

Python Programming

Python Programming. Week 3 - Wednesday. Starter. YESTERDAY. Date &amp; Time Library Conditional statements. REMInders. Today. Conditionals &amp; Control flow Understand what control flow is Recognise and practice using 6 comparators (==, !=, &lt;=, &gt;=, &lt;, &gt;) Explain what a comparator is

285 views • 11 slides

Python Programming

Chapter 10: Dictionaries. Python Programming. Saad Bani Mohammad Department of Computer Science Al al-Bayt University. 1 st 2011/2012. Dictionaries.

423 views • 16 slides

Python programming

Python programming

Python programming. Introduction to the JES environment and basics of Python. Reading: Chapters 1, 2 from “Introduction to Computing and Programming in Python”. Python. The programming language we will be using is called Python http://www.python.org

703 views • 34 slides

Python programming

Python programming. Introduction to the JES environment and basics of Python. Python. The programming language we will be using is called Python http://www.python.org It’s used by companies like Google, Industrial Light &amp; Magic, Nextel, and others

444 views • 16 slides

python programming

python programming

Get the best Python training in Bangalore. Apponix is proud to say that its is one of the top Python training provider in Bangalore, we provide best training experience and results to our valued students, All our trainers are very experienced IT professionals and love to share their practical knowledge with the students.

164 views • 5 slides

Python programming

Python programming. Using the JES picture functions and defining new functions. Review. Python – what kind of animal? JES environment command area arithmetic print command variables and the assignment statement Functions sqrt() str() showInformation() requestInteger().

302 views • 26 slides

Python Basics

239 views • 18 slides

Python Programming

Chapter 9: Tuples. Python Programming. Saad Bani Mohammad Department of Computer Science Al al-Bayt University. 1 st 2011/2012. Mutability and Tuples.

225 views • 17 slides

SlideTeam

  • Programming Python Code
  • Popular Categories

Powerpoint Templates

Icon Bundle

Kpi Dashboard

Professional

Business Plans

Swot Analysis

Gantt Chart

Business Proposal

Marketing Plan

Project Management

Business Case

Business Model

Cyber Security

Business PPT

Digital Marketing

Digital Transformation

Human Resources

Product Management

Artificial Intelligence

Company Profile

Acknowledgement PPT

PPT Presentation

Reports Brochures

One Page Pitch

Interview PPT

All Categories

Powerpoint Templates and Google slides for Programming Python Code

Save your time and attract your audience with our fully editable ppt templates and slides..

Programming Python Code In Powerpoint And Google Slides Cpb

Presenting Programming Python Code In Powerpoint And Google Slides Cpb slide which is completely adaptable. The graphics in this PowerPoint slide showcase four stages that will help you succinctly convey the information. In addition, you can alternate the color, font size, font type, and shapes of this PPT layout according to your content. This PPT presentation can be accessed with Google Slides and is available in both standard screen and widescreen aspect ratios. It is also a useful set to elucidate topics like Programming Python Code. This well structured design can be downloaded in different formats like PDF, JPG, and PNG. So, without any delay, click on the download button now.

UI Coding Icon For Programming Language

Introducing our premium set of slides with UI Coding Icon For Programming Language. Ellicudate the Three stages and present information using this PPT slide. This is a completely adaptable PowerPoint template design that can be used to interpret topics like UI Coding Icon, Programming Language. So download instantly and tailor it with your information.

Web Development Coding Icon For Programming Language

Introducing our premium set of slides with Web Development Coding Icon For Programming Language. Ellicudate the Three stages and present information using this PPT slide. This is a completely adaptable PowerPoint template design that can be used to interpret topics like Web Development Coding Icon, Programming Language. So download instantly and tailor it with your information.

UI Coding For Programming Language Colored Icon In Powerpoint Pptx Png And Editable Eps Format

This vibrant PowerPoint icon features a coding language symbol, perfect for presentations on UI programming and development. The bold colors and clean design make it easy to incorporate into any slide, while the detailed image accurately represents the topic at hand. Add a touch of professionalism to your slides with this eye-catching icon.

UI Coding For Programming Language Monotone Icon In Powerpoint Pptx Png And Editable Eps Format

This Monotone powerpoint icon is perfect for representing UI coding in programming language presentations. With its sleek and minimalist design, it conveys the technical aspect of UI coding while maintaining a professional and modern look. Use it to enhance your slides and make a strong visual impact.

Man doing python coding for big data governance

Presenting this set of slides with name Man Doing Python Coding For Big Data Governance. This is a one stage process. The stages in this process are Big Data Governance, Analytics, Dashboard. This is a completely editable PowerPoint presentation and is available for immediate download. Download now and impress your audience.

Coding Challenge Questions Python In Powerpoint And Google Slides Cpb

Presenting our Coding Challenge Questions Python In Powerpoint And Google Slides Cpb PowerPoint template design. This PowerPoint slide showcases three stages. It is useful to share insightful information on Coding Challenge Questions Python This PPT slide can be easily accessed in standard screen and widescreen aspect ratios. It is also available in various formats like PDF, PNG, and JPG. Not only this, the PowerPoint slideshow is completely editable and you can effortlessly modify the font size, font type, and shapes according to your wish. Our PPT layout is compatible with Google Slides as well, so download and edit it as per your knowledge.

Training Program To Improve Data Analysis Skill Using Python Business Development Training

The slide showcases training plan for improving data analysis skills. The key training topics covered will be Python and SQL for data extraction, data interpretation and data representation for improving operational efficiency. Present the topic in a bit more detail with this Training Program To Improve Data Analysis Skill Using Python Business Development Training. Use it as a tool for discussion and navigation on Training Program, Improve Data, Analysis Skill, Using Python And Sql. This template is free to edit as deemed fit for your organization. Therefore download it now.

Skill Development Programme Training Program To Improve Data Analysis Skill Using Python And SQL

The slide showcases training plan for improving data analysis skills. The key training topics covered will be Python and SQL for data extraction, data interpretation and data representation for improving operational efficiency. Present the topic in a bit more detail with this Skill Development Programme Training Program To Improve Data Analysis Skill Using Python And SQL. Use it as a tool for discussion and navigation on Data Manipulation, Data Distribution, Regression Models. This template is free to edit as deemed fit for your organization. Therefore download it now.

Python programming learning five year roadmap

Presenting Python Programming Learning Five Year Roadmap PowerPoint slide. This PPT theme is available in both 4,3 and 16,9 aspect ratios. This PowerPoint template is customizable so you can modify the font size, font type, color, and shapes as per your requirements. This PPT presentation is Google Slides compatible hence it is easily accessible. You can download and save this PowerPoint layout in different formats like PDF, PNG, and JPG.

Python programming learning four quarter roadmap

Presenting Python Programming Learning Four Quarter Roadmap PowerPoint Template. This PPT presentation is Google Slides compatible hence it is easily accessible. You can download and save this PowerPoint layout in different formats like PDF, PNG, and JPG. This PPT theme is available in both 4,3 and 16,9 aspect ratios. This PowerPoint template is customizable so you can modify the font size, font type, color, and shapes as per your requirements.

Python programming learning half yearly roadmap

Presenting Python Programming Learning Half Yearly Roadmap PowerPoint slide which is 100 percent editable. You can change the color, font size, font type, and shapes of this PPT layout according to your needs. This PPT template is compatible with Google Slides and is available in both 4,3 and 16,9 aspect ratios. This ready to use PowerPoint presentation can be downloaded in various formats like PDF, JPG, and PNG.

Python programming learning six months roadmap

Presenting Python Programming Learning Six Months Roadmap PowerPoint slide. This PPT presentation is Google Slides compatible hence it is easily accessible. This PPT theme is available in both 4,3 and 16,9 aspect ratios. This PowerPoint template is customizable so you can modify the font size, font type, color, and shapes as per your requirements. You can download and save this PowerPoint layout in different formats like PDF, PNG, and JPG.

Python programming learning three months roadmap

Presenting Python Programming Learning Three Months Roadmap PowerPoint slide. This PPT slide is available at 4,3 and 16,9 aspect ratios. You can download this PPT theme in various formats like PDF, PNG, and JPG. This PowerPoint template is completely editable and you can modify the font size, font type, and shapes as per your requirements. Our PPT layout is compatible with Google Slides.

Python coding challenges ppt powerpoint presentation professional design inspiration cpb

Presenting our Python Coding Challenges Ppt Powerpoint Presentation Professional Design Inspiration Cpb PowerPoint template design. This PowerPoint slide showcases five stages. It is useful to share insightful information on Python Coding Challenges This PPT slide can be easily accessed in standard screen and widescreen aspect ratios. It is also available in various formats like PDF, PNG, and JPG. Not only this, the PowerPoint slideshow is completely editable and you can effortlessly modify the font size, font type, and shapes according to your wish. Our PPT layout is compatible with Google Slides as well, so download and edit it as per your knowledge.

Google Reviews

Got any suggestions?

We want to hear from you! Send us a message and help improve Slidesgo

Top searches

Trending searches

presentation on python programming

suicide prevention

8 templates

presentation on python programming

46 templates

presentation on python programming

tropical rainforest

29 templates

presentation on python programming

spring season

34 templates

presentation on python programming

american football

16 templates

presentation on python programming

32 templates

Programming Presentation templates

If you're the type of person who loves to solve puzzles and think analytically, then programming might just be the perfect hobby for you programming gives you the opportunity to create, explore and work with logic to make all sorts of neat projects, from apps and websites to video games and machinery. enter this wonderful world by checking out our google slides themes & powerpoint templates about programming..

Programming Lesson presentation template

Programming Lesson

If you teach programming languages and related issues, download and personalize this template to prepare your lesson. The fonts look computer-like, and it’s very creative. Insert some info about the features of the topic, assignments and support them with visual aids, such as bar graphs.

Programming Language Workshop for Beginners presentation template

Programming Language Workshop for Beginners

Go from “Hello World!” to a master in programming with this creative template that looks like code line. The amazing design works perfect for a programming workshop because it includes editable resources and a layout that makes understanding code lines a very easy and visual experience. In addition, the color...

How to Code Workshop presentation template

Premium template

Unlock this template and gain unlimited access

How to Code Workshop

Are you an expert of Java? Yes, it's a beautiful island in Indonesia and more than half of the population of this country lives there... No! Well, yes, those facts are true, but we were talking about the programming language! We think workshops on how to code are a necessity,...

Computer Science & Mathematics Major For College: Computer Science & Programming presentation template

Computer Science & Mathematics Major For College: Computer Science & Programming

Show future students the wonders of computer science and what they can achieve if they join a career in this incredible degree. With these slides you can speak about both technical and simple concepts and they will all be quickly understood! Editing them is as easy as printing Hello world!...

Introduction to Java Programming for High School presentation template

Introduction to Java Programming for High School

Teaching programming to High School students is undoubtedly a great way to give them useful and practical skills for life! And to help you out with this task, Slidesgo has created this template for an introduction to Java programming for you. Not only is it extremely attractive with its neon...

Java Programming Workshop presentation template

Java Programming Workshop

Programming... it's hard, it must be said! It won't be after you use this presentation! If you are an expert in Java and programming, share your knowledge in the form of a workshop. This template is designed for you to include everything you know about Java and show it to...

New Operating System Design Pitch Deck presentation template

New Operating System Design Pitch Deck

Windows, Android, macOS... the list of operating systems is quite long, and without them, we wouldn't have be using electronic devices today. Yeah, no computers, no smartphones! As technology continues to evolve at a rapid pace, there is a growing demand for new and innovative operating systems that can keep...

Work Program Project Proposal presentation template

Work Program Project Proposal

Download the "Work Program Project Proposal" presentation for PowerPoint or Google Slides. A well-crafted proposal can be the key factor in determining the success of your project. It's an opportunity to showcase your ideas, objectives, and plans in a clear and concise manner, and to convince others to invest their...

Code Hacker Lesson for Middle School presentation template

Code Hacker Lesson for Middle School

Don't let the name mislead you! If you're a middle school teacher and your mission is to educate your students in the use of computers, this template can help you make your lesson more interesting! The visual content revolves around programming (yes, and hackers), so you might want to talk...

Introduction to Coding Workshop presentation template

Introduction to Coding Workshop

Have you ever wondered what goes on behind the scenes of your favorite apps, websites, and computer programs? No? That's because you're an expert in coding, and are about to prepare an introductory workshop to coding. Alright! Dive headfirst into this editable template and transform the slides into useful resources...

Silicon Valley Programmer Portfolio presentation template

Silicon Valley Programmer Portfolio

Download the "Silicon Valley Programmer Portfolio" presentation for PowerPoint or Google Slides. When a potential client or employer flips through the pages of your portfolio, they're not just looking at your work; they're trying to get a sense of who you are as a person. That's why it's crucial to...

Abstract Lines Thesis Defense Program Brochure presentation template

Abstract Lines Thesis Defense Program Brochure

The defense of your thesis is a very important step in your professional career, arguably the most important. You already have the first part of the process: having your thesis done. Now, the next step is to stand out in the defense and surprise the jury with your work. A...

Introduction to Java Programming Language for Middle School presentation template

Introduction to Java Programming Language for Middle School

Are you ready to take coding to the next level? Java programming may just be the answer you've been searching for. As a versatile language used in engineering and various platforms such as Android, Java is a great language to learn in middle school. With the help of this Google...

Colombian Code and Programming Learning Center presentation template

Colombian Code and Programming Learning Center

Do you know how to program? All the secrets of codes and programming can be mastered if well understood. Maybe a teaching center can help with that! A little bird has told us that you own a Code and Programming Learning Center and you need to present it to new...

Senior Frontend Developer Portfolio presentation template

Senior Frontend Developer Portfolio

Download the "Senior Frontend Developer Portfolio" presentation for PowerPoint or Google Slides. When a potential client or employer flips through the pages of your portfolio, they're not just looking at your work; they're trying to get a sense of who you are as a person. That's why it's crucial to...

Brackets Lesson for Coding and Programming presentation template

Brackets Lesson for Coding and Programming

Learning the basics of coding and programming just got a lot easier with this engaging template about the importance of brackets. Let's go through the basics together, using illustrations and visuals in colorful tones to make the learning process even more fun! From understanding what brackets mean to knowing where...

Programming Language Master's Degree presentation template

Programming Language Master's Degree

There are many languages. The language of music, the language of feelings or the type of language we are using to describe this template. Okay, you guessed it! The next template is about one type of language. But which one? If we tell you Java or Python you might be...

New Operating System Design Pitch Deck Infographics presentation template

New Operating System Design Pitch Deck Infographics

Will there be a day when Slidesgo releases an operating system? Like, for example, SlidesgOS? Hmmm, the name doesn't sound right, it's like we just multiplied... While we think of a better name, why don't you check out these infographics? With titles making use of those angle brackets you see...

  • Page 1 of 5

New! Make quick presentations with AI

Slidesgo AI presentation maker puts the power of design and creativity in your hands, so you can effortlessly craft stunning slideshows in minutes.

presentation on python programming

Register for free and start editing online

  • Mailing List

Practical Business Python

Taking care of business, one python script at a time

Creating Powerpoint Presentations with Python

Posted by Chris Moffitt in articles   

Introduction

Love it or loathe it, PowerPoint is widely used in most business settings. This article will not debate the merits of PowerPoint but will show you how to use python to remove some of the drudgery of PowerPoint by automating the creation of PowerPoint slides using python.

Fortunately for us, there is an excellent python library for creating and updating PowerPoint files: python-pptx . The API is very well documented so it is pretty easy to use. The only tricky part is understanding the PowerPoint document structure including the various master layouts and elements. Once you understand the basics, it is relatively simple to automate the creation of your own PowerPoint slides. This article will walk through an example of reading in and analyzing some Excel data with pandas, creating tables and building a graph that can be embedded in a PowerPoint file.

PowerPoint File Basics

Python-pptx can create blank PowerPoint files but most people are going to prefer working with a predefined template that you can customize with your own content. Python-pptx’s API supports this process quite simply as long as you know a few things about your template.

Before diving into some code samples, there are two key components you need to understand: Slide Layouts and Placeholders . In the images below you can see an example of two different layouts as well as the template’s placeholders where you can populate your content.

In the image below, you can see that we are using Layout 0 and there is one placeholder on the slide at index 1.

PowerPoint Layout 0

In this image, we use Layout 1 for a completely different look.

PowerPoint Layout 1

In order to make your life easier with your own templates, I created a simple standalone script that takes a template and marks it up with the various elements.

I won’t explain all the code line by line but you can see analyze_ppt.py on github. Here is the function that does the bulk of the work:

The basic flow of this function is to loop through and create an example of every layout included in the source PowerPoint file. Then on each slide, it will populate the title (if it exists). Finally, it will iterate through all of the placeholders included in the template and show the index of the placeholder as well as the type.

If you want to try it yourself:

Refer to the input and output files to see what you get.

Creating your own PowerPoint

For the dataset and analysis, I will be replicating the analysis in Generating Excel Reports from a Pandas Pivot Table . The article explains the pandas data manipulation in more detail so it will be helpful to make sure you are comfortable with it before going too much deeper into the code.

Let’s get things started with the inputs and basic shell of the program:

After we create our command line args, we read the source Excel file into a pandas DataFrame. Next, we use that DataFrame as an input to create the Pivot_table summary of the data:

Consult the Generating Excel Reports from a Pandas Pivot Table if this does not make sense to you.

The next piece of the analysis is creating a simple bar chart of sales performance by account:

Here is a scaled down version of the image:

PowerPoint Graph

We have a chart and a pivot table completed. Now we are going to embed that information into a new PowerPoint file based on a given PowerPoint template file.

Before I go any farther, there are a couple of things to note. You need to know what layout you would like to use as well as where you want to populate your content. In looking at the output of analyze_ppt.py we know that the title slide is layout 0 and that it has a title attribute and a subtitle at placeholder 1.

Here is the start of the function that we use to create our output PowerPoint:

This code creates a new presentation based on our input file, adds a single slide and populates the title and subtitle on the slide. It looks like this:

PowerPoint Title Slide

Pretty cool huh?

The next step is to embed our picture into a slide.

From our previous analysis, we know that the graph slide we want to use is layout index 8, so we create a new slide, add a title then add a picture into placeholder 1. The final step adds a subtitle at placeholder 2.

Here is our masterpiece:

PowerPoint Chart

For the final portion of the presentation, we will create a table for each manager with their sales performance.

Here is an image of what we’re going to achieve:

PowerPoint Table

Creating tables in PowerPoint is a good news / bad news story. The good news is that there is an API to create one. The bad news is that you can’t easily convert a pandas DataFrame to a table using the built in API . However, we are very fortunate that someone has already done all the hard work for us and created PandasToPowerPoint .

This excellent piece of code takes a DataFrame and converts it to a PowerPoint compatible table. I have taken the liberty of including a portion of it in my script. The original has more functionality that I am not using so I encourage you to check out the repo and use it in your own code.

The code takes each manager out of the pivot table and builds a simple DataFrame that contains the summary data. Then uses the df_to_table to convert the DataFrame into a PowerPoint compatible table.

If you want to run this on your own, the full code would look something like this:

All of the relevant files are available in the github repository .

One of the things I really enjoy about using python to solve real world business problems is that I am frequently pleasantly surprised at the rich ecosystem of very well thought out python tools already available to help with my problems. In this specific case, PowerPoint is rarely a joy to use but it is a necessity in many environments.

After reading this article, you should know that there is some hope for you next time you are asked to create a bunch of reports in PowerPoint. Keep this article in mind and see if you can find a way to automate away some of the tedium!

  • ← Best Practices for Managing Your Code Library
  • Adding a Simple GUI to Your Pandas Script →

Subscribe to the mailing list

Submit a topic.

  • Suggest a topic for a post
  • Pandas Pivot Table Explained
  • Common Excel Tasks Demonstrated in Pandas
  • Overview of Python Visualization Tools
  • Guide to Encoding Categorical Values in Python
  • Overview of Pandas Data Types

Article Roadmap

We are a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for us to earn fees by linking to Amazon.com and affiliated sites.

PSF Supporting Member

  • Python Basics
  • Interview Questions
  • Python Quiz
  • Popular Packages
  • Python Projects
  • Practice Python
  • AI With Python
  • Learn Python3
  • Python Automation
  • Python Web Dev
  • DSA with Python
  • Python OOPs
  • Dictionaries
  • Creating and updating PowerPoint Presentations in Python using python - pptx
  • Creating Interactive Slideshows in Jupyter Notebooks
  • PYGLET – Accessing Event types of Formatted Document
  • Introduction to pyglet library for game development in Python
  • PYGLET – Setting Style to whole Formatted Document
  • PYGLET – Setting Paragraph Style of Formatted Document
  • How to Add Audio to Powerpoint Presentation
  • How to Save PowerPoint Presentations as PDF Files using MS PowerPoint?
  • How to Edit a Powerpoint Presentation?
  • What is the purpose of the PPTM file in PowerPoint?
  • Applying Transitions to Slides in MS PowerPoint
  • Formatting Text on a Slide in a PPT using Java
  • Converting the Slides of a PPT into Images using Java
  • What is the use of format in PowerPoint?
  • How to use Animation Pane in MS PowerPoint?
  • How to Install Pyglet in Python on Linux?
  • How to Add different Slide Designs in MS PowerPoint?
  • What is difference Between PPT and PPTX?
  • How to Change Slide Layout in MS PowerPoint ?
  • Java Program to Create a Blank PPT Document
  • Adding new column to existing DataFrame in Pandas
  • Python map() function
  • Read JSON file using Python
  • How to get column names in Pandas dataframe
  • Taking input in Python
  • Read a file line by line in Python
  • Dictionaries in Python
  • Enumerate() in Python
  • Iterate over a list in Python
  • Different ways to create Pandas Dataframe

Creating and updating PowerPoint Presentations in Python using python – pptx

python-pptx is library used to create/edit a PowerPoint (.pptx) files. This won’t work on MS office 2003 and previous versions.  We can add shapes, paragraphs, texts and slides and much more thing using this library.

Installation: Open the command prompt on your system and write given below command:

Let’s see some of its usage:

Example 1: Creating new PowerPoint file with title and subtitle slide.

Adding title and subtitle to the powerpoint

Example 2: Adding Text-Box in PowerPoint.

Adding text box to the powerpoint

Example 3: PowerPoint (.pptx) file to Text (.txt) file conversion.

presentation on python programming

Example 4: Inserting image into the PowerPoint file.

Adding images to the powerpoint

Example 5: Adding Charts to the PowerPoint file.

Adding charts to the powerpoint

Example 6: Adding tables to the PowerPoint file.

Adding table to the powerpoint

Please Login to comment...

Similar reads.

  • python-modules
  • python-utility

advertisewithusBannerImg

Improve your Coding Skills with Practice

 alt=

What kind of Experience do you want to share?

Python Programming Language

Dr.YNM

Learn Python programming in simple steps Read less

presentation on python programming

Recommended

More related content, what's hot, what's hot ( 20 ), viewers also liked, viewers also liked ( 20 ), similar to python programming language, similar to python programming language ( 20 ), more from dr.ynm, more from dr.ynm ( 20 ), recently uploaded, recently uploaded ( 20 ).

  • 1. PYTHON-PROGRAMMING YNM
  • 2. What is Python? • Python is a general purpose interpreted interactive object oriented and high level programming language. • It was first introduced in 1991 by Guido van Rossum , a Dutch computer programmer. • The language places strong emphasis on code reliability and simplicity so that the programmers can develop applications rapidly 10/27/15 [email protected]
  • 3. contd.. • Python is multi-paradigm programming language ,which allows user to code in several different programming styles. • Python supports cross platform development and is available through open source. • Python is widely used for scripting in Game menu applications effectively. 10/27/15 [email protected]
  • 4. contd.. • Python can be easily integrated with C/C++ CORBA, ActiveX and Java. • CPython is a python integrated with C/C++ language. • Similarly JPython is a purely integrated language where Java and Python code can interchangeably use inline in the program. 10/27/15 [email protected]
  • 5. Advantages of Python • Most programs in Python require considerably less number of lines of code to perform the same task compared to other languages like C .So less programming errors and reduces the development time needed also. • Though Perl is a powerful language ,it is highly syntax oriented .Similarly C also. 10/27/15 [email protected]
  • 6. Why to Learn Python • There are large number of high-level programming languages like C ,C++,Java etc.But when compared to all these languages Python has simplest Syntax, availability of libraries and built-in modules. • Python comes with an extensive collection of third party resources that extend the capabilities of the language. 10/27/15 [email protected]
  • 7. contd.. • Python can be used for large variety of tasks like Desktop applications ,Data base applications,network programming ,game programming and even mobile development also. • Python is also a cross platform language which means that the code written for one operating system like Windows ,will work equally well with Linux or MacOS without any changes to the python code. 10/27/15 [email protected]
  • 8. INSTALLING PYTHON ON YOUR PC • To learn this language first ,you have to download the software which is the Python Interpreter. • Presently the version in use is Python 3.x But you can also use Python 2.x ,like 2.7..etc .This depends on your system and your interest. To download the Python interpreter go to the site http://www.python.org/downloads and click on the suitable icon. 10/27/15 [email protected]
  • 9. contd.. • The website appears as shown below. 10/27/15 [email protected]
  • 10. contd.. • From the website you can download the suitable version based on • your OS (whether the OS is Windows ,MacOS or Linux). • And the Processor 32 bit or 64 bit. • For ex: if you are using 64-bit Windows system ,you are likely to download Windowsx86-64MSI Installer. • So just click on the link and download and install the Python Interpreter. 10/27/15 [email protected]
  • 11. contd.. • This Python shell allows us to use Python in interactive mode. • The shell waits for a command from the user ,executes it and returns the result. 10/27/15 [email protected]
  • 12. IDLE • IDLE is a graphical user interface for doing Python development, and is a standard and free part of the Python system. • It is usually referred to as an Integrated Development Environment (IDE). • One can write the Python code or script using the IDLE which is like an editor.This comes along with Python bundle. 10/27/15 [email protected]
  • 13. contd.. The only thing to do is that we have to launch the IDLE program . • While the Python shell allows the user to work in interactive mode, the Idle allows to write the code and save it with .py extension. For Ex: myProg_py. • This file is known as Python script. 10/27/15 [email protected]
  • 14. contd.. • Once the program is saved ,it can be executed either by clicking the Run module or F5. • If there are no errors you observe the results. 10/27/15 [email protected]
  • 15. contd.. • The Screenshot for IDLE will be as shown below. The >>> is the prompt, telling you Idle is waiting for you to type something. 10/27/15 [email protected]
  • 16. Your First Program • To develop the Python program ,click on the File and select NewFile. • This will open a new text editor where you can write your first program. • # Prints the words Hello Python print(“Hello Python”) print(“Its nice learning Python”) print(“Python is easy to learn”) 10/27/15 [email protected]
  • 17. contd.. • In the above program ,the lines appear after the # sign are treated as comments. They are ignored and not executed by Python interpreter. This will help only to improve the readability of the program. • After typing the code save this program with an extension .py .For Ex: FirstProg.py • Now press either F5 or click on Run module. 10/27/15 [email protected]
  • 18. contd.. • After execution you find the output as Hello Python Its nice learning Python Python is easy to learn. 10/27/15 [email protected]
  • 19. Variables and Operators • Variables are the names given to data that we need to store and manipulate in our program. • For example ,to store the age of the user ,we can write a variable userAge and it is defined as below. userAge = 0 or userAge = 50 After we define userAge ,the program will allocate some memory to store this data. 10/27/15 [email protected]
  • 20. contd.. • Afterwards this variable can be accessed by referring its name userAge. • Every time we declare a variable ,some initial value must be given to it. • We can also define multiple variables at a time. For ex: userAge, userName=30,’Peter’ This is same as userAge=30 userName=‘Peter’ 10/27/15 [email protected]
  • 21. contd.. • Some precautions: The user name can contain any letters (lower case or upper case) numbers or underscores(-) but the first character shouldn’t be a number • For Ex: userName,user_Name,user_Name2 etc.. Are valid. • But 2user_name ,2userName ..are not valid 10/27/15 [email protected]
  • 22. contd.. • Variable names are case sensitive .username and userNAME are not same. • Normally two conventions are used in Python to denote variables. • Camel case notation or use underscores. • Camel case is the practice of writing the compound words with mixed casing.For ex:”thisIsAvariableName” • Another is to use underscores (-). 10/27/15 [email protected]
  • 23. contd.. • This separates the words.For example: “user_Name_variable” • In the above example userAge=30,the ‘=‘ sign is known as Assignment Sign • It means ,we are assigning the value on the right side of the = sign to the variable on the left. • So the statements x=y and y=x have different meanings in programming. 10/27/15 [email protected]
  • 24. contd.. • For example ,open your IDLE editor and type the following program. x=5 y=10 x=y print(“x=“,x) Print(‘y=“,y) Now save this program with .py extension. For example myprog1.py 10/27/15 [email protected]
  • 25. contd.. • Run the program either by clicking . Runmodule or F5 The output should be as below. x=10 y=10 Here in the program you have assigned x=y in the third line.So the value of x is changed to10 while the value of y do not change . 10/27/15 [email protected]
  • 26. contd.. • Suppose you change the third line from x=y to y=x, mathematically x=y and y=x may be same .But it is not same in programming. • After changing ,you again save your program and Run the module as done above.What is the output you expect? • Surprisingly x=5 ,y=5 will be the output. are you convinced with the output? 10/27/15 [email protected]
  • 27. Basic Operators • Python accepts all the basic operators like + (addition),(subtraction),*(multiplication),/ (division),//(floor division),%(modulus) and **(exponent). • For example ,if x= 7,y=2 addition: x+y=9 subtraction:x-y=5 Multiplication:x*y=14 Division: x/y=3.5 10/27/15 [email protected]
  • 28. contd • Floor division: x // y=3(rounds off the answer to the nearest whole number) • Modulus: x%y= 1(Gives the remainder when 7 is divided by 2 • Exponent : x**y=49(7 to the power of 2) 10/27/15 [email protected]
  • 29. Additional assignment Operators • +=: x+= 2 is same as equal to x=x+2 • Similarly for subtraction: x-=2 is same as x=x-2 10/27/15 [email protected]
  • 30. Data Types • Python accepts various data types like Integer, Float and String. • Integers are numbers with no decimal parts like 2 ,-5 , 27 ,0 ,1375 etc.. • Float refers to a number that has decimal parts.Ex: 1.2467 ; -0.7865 ; 125.876 • userHeight = 12.53 • userWeight = 65.872 10/27/15 [email protected]
  • 31. contd.. • String: string refers to text.Strings are defined within single quotes. • For Ex: Variable Name = ‘initialvalue’ • VariableName=“initial value” • userName=‘peter’ • userSpouseName=“Mary” • userAge =“35” here “35” is a string 10/27/15 [email protected]
  • 32. contd.. • Multiple substrings can be combined by using the concatenate sign(+) • Ex:”Peter”+ “Lee” is equivalent to the string “PeterLee” 10/27/15 [email protected]
  • 33. Type Casting • Type casting helps to convert from one data type to another .i.e from integer to a string or vice versa. • There are three built in functions in Python int() ; str() ; float() • To change a float to an integer type int(7.3256).The output is 7 • To change a string into integer int(“4”).The output is 4 10/27/15 [email protected]
  • 34. contd.. • Ex: int(“RAM”) ----- returns syntax error • Int(“3.7654”) -------returns syntax error • The str() function converts an integer or a float to a string. • Ex: str(82.1) The output is “82.1” • Ex: str(757) The output is “757” • Ex: str(Ram) The output is “Ram” 10/27/15 [email protected]
  • 35. LIST • A List in Python is a collection data which are normally related. • Instead of storing a data as separate variables ,it can be stored as a LIST. • For ex: to store the age of 4 users , instead of storing them as user1Age,user2Age,user3Age and user4Age we can create a List of this data. • To some extent, lists are similar to arrays in C. Difference between them is that all the items belonging to a list can be of different data type.10/27/15 [email protected]
  • 36. contd.. • To declare a List: ListName=[initial values]. Note ,always square brackets[] are used to declare a List. userAge =[20,42,23,25] • A List can also be declared without assigning any initial value to it. • listName=[]. This is an empty list with no items in it. 10/27/15 [email protected]
  • 37. contd.. • To add items to the List ,we use append(). • The individual items of the List are accessed by their indexes.The index always starts from 0. • For ex; useAge=[20,25,35,45,65,55] here userAge[0]= 20,userAge[2]=35. • Similarly the index -1 denotes the last item • userAge[-1]=55 and userAge[-2]=65 10/27/15 [email protected]
  • 38. SLICE • To access a set of items in a List we use Slice. • The notation used is x:y. • Whenever we use slice notation inPython, the item at the start index is always included ,but the item at the end is always excluded i.e y-1 is considered. • For ex:userAge=[15,25,30,45,50.65.55] the userAge[0:4] gives values from index 0 to 3 i.e 15,25,30,45 10/27/15 [email protected]
  • 39. Add and Remove items • To add items the append() function is useful. • For ex :userAge.append(100) will add the value 100 to the List at the end. Now the new List is userAge=[15,25,30,45,50.65.55,100] • To remove any value from the List we write dellistName[index of item to be deleted] • For ex: del userAge[2] will give a new List userAge=[15,25,45,50,65,55,100] 10/27/15 [email protected]
  • 40. Program • # declare the list myList[2,5,4,5,”Ram”] • # to print the entire list print(‘myList’) • # to print the third item print(myList[3]) The output is “Ram” • # to print the last but one item print(myList[-2]) 10/27/15 [email protected]
  • 41. Tuple • Tuples are also a type of Lists.But the difference is they can’t be modified. • A tuple consists of a number of values separated by commas. Unlike lists, however, tuples are enclosed within parentheses(). • The main differences between lists and tuples are: • Lists are enclosed in brackets [ ] and their elements and size can be changed, while tuples are enclosed in parentheses ( ( ) ) and cannot be updated. • Tuples can be thought of as read-only lists. 10/27/15 [email protected]
  • 42. contd.. • Declaring a Tuple tupleName=( ‘Raju',786 , 2.23, ‘cdef',70.2 ) monthsOfYear(“Jan”,”Feb”,”March”,”April”) • monthsOfYear[0]=“Jan” • monthsOfYear[-1]= “April” 10/27/15 [email protected]
  • 43. contd.. • print tuple: # Prints complete list print • tuple[0] : # Prints first element of the list • print tuple[1:3]: # Prints elements starting from 2nd till 3rd print • tuple[2:] : # Prints elements starting from 3rd element • print tinytuple * 2 : # Prints list two times 10/27/15 [email protected]
  • 44. Dictionary • Dictionary is a collection of related data PAIRS. • The general Syntax is dictionaryName={dictionarykey:data} The same dictionary key should not be used twice • For Ex: to store the username and age of 4 users we can write • myDictionary={“peter”:25,”Ram”:15,”Carl”:5 0,”Kundan”: 20} 10/27/15 [email protected]
  • 45. contd… • Dictionary can also be declared using “dict()” method. • userNameAndAge=dict(peter=25,Ram=20,Carl =30, Krish=“not available”) • Here round brackets parenthesis) are used instead of curly brackets. • dictionaryName={ } denotes an empty dictionary with no items init 10/27/15 [email protected]
  • 46. Add items to Dictionary • To add items to a dictionary the syntax is dictionaryName[dictionarykey]=data. To add “Sam”=40 to the dictionary , userNameAndAge[“Sam”]=40 • Now the dictionary will become userNameAndAge=dict(peter=25,Ram=20,Car l=30, Krish=“not available”,Sam=40) 10/27/15 [email protected]
  • 47. contd.. • To delete or remove items from a dictionary the syntax is del dictionaryName[dictionarykey] • Ex: To remove “Ram”:20 the syntax is del usernameAndAge[‘’Ram”] • Now the dictionary is userNameAndAge={“peter”:25,”Carl”:30, “Krish”:“not available”,”Sam”:40} 10/27/15 [email protected]
  • 48. Declare Dictionary –Alternative way • Dictionary can also be declared by alternative method • myDict={“one”:1.45,5.8:”TwopointFive”,3:”+”,4.5:2} print(mydict) The output is {2.5:’TwopointFive’,3:’+’:4.5,4.5:2} 10/27/15 [email protected]
  • 49. Condition Statements • To change the flow of control ,normally we use some conditional statements in a program .The flow of the program is based on whether the condition is met or not . • The most common condition statement is Comparison statement which is denoted by (= =) sign. • For ex: when you are writing a==b ,means you are asking the program to check whether the value of a is equals to that of b or not. 10/27/15 [email protected]
  • 50. contd.. • The other comparison statements are “not equals” (!=) “smaller than”(<) “greater than”(>) “greater than or equal to (>=) Examples: 8!= 4 ----Not equals 6>=2 ----Greater than or equal to 7>2 ---Greater than 4<9 – Less than or equal to 10/27/15 [email protected]
  • 51. Logical Operators • There are three logical operators in Python • And , or ,not • The and operator returns True if all the conditions are met ,else it will return False. • The or operator returns true if atleast one condition is met.Else it will return false. • The not operator returns True if the condition after the not keyword is false.Else it will return False. 10/27/15 [email protected]
  • 52. If statement • It is one of the commonly used control flow statements. • It allows the program to evaluate if certain condition is met. And to perform the appropriate action based on the result of the evaluation • For example , if condition 1 is met do task A elif condition 2 is met do task B elif stands for else if and we can have as many elif statements as we like 10/27/15 [email protected]
  • 53. Program • Open your Idle and type the program • userInput=input(“Enter 1 or 2”) if userInput == “1”: print(“Hello Python”) print(“how are you”) elif userInput == “2”: print(“python great”) print(“I Love Python”) else: print(“ you entered invalid number”) 10/27/15 [email protected]
  • 54. For Loop • The For Loop executes a block of code repeatedly until the condition in the for statement is no longer valid. • In Python ,an iterable refers to anything that can be looped over ,such as a string ,list or Tuple. • The syntax for looping through an iterable is : for an iterable print(a) 10/27/15 [email protected]
  • 55. contd.. • Ex: pets = [‘cats’,’dogs’,’rabbits’,’hamsters’] for myPets in pets: print(myPets) In this program,first we declared the list pets and give the members ‘cats’,’dogs’,’rabbits’ and ‘hamsters’.Next the statement for myPets: loops through the pets list and assigns each member in the list to the variable myPets. 10/27/15 [email protected]
  • 56. contd.. • If we run the program ,the output will be cats dogs rabbits hamsters • It is also possible to display the index of the members in the List.For this the function enumerate() is used. • For index,myPets in enumerate(pets): • print(index,myPets) 10/27/15 [email protected]
  • 57. contd.. • The output is: 0 cats 1 dogs 2 rabbits 3 hamsters 10/27/15 [email protected]
  • 58. Looping through a sequence of Numbers • To loop through a sequence of numbers ,the built-in range() function is used. • The range() function generates a list of numbers and has the syntax : range(start,end,step). • If start is not mentioned ,the numbers generated will start from zero. • Similarly if step is not given , alist of consecutive numbers will be generated (i.e step=1) 10/27/15 [email protected]
  • 59. contd.. • For ex: • Range(4) will generate the List[0,1,2,3,] • Range(3,9) will generate a List[3,4,5,6,7,8] • Range(4,10,2) will generate List[4,6,8] 10/27/15 [email protected]
  • 60. Example • To check the working of range function with for loop type the following script on Idle. • for i in range(5); print(i) The output will be: 0 1 2 3 4 10/27/15 [email protected]
  • 61. While Loop • A while loop repeatedly executes instructions inside the loop while a certain condition remains true. • The syntax of a while loop is while the condition is true do the Task A For Ex: Counter= 5 While counter > 0: 10/27/15 [email protected]
  • 62. contd.. • print(‘counter=‘,counter) counter = counter-1 When you run the program the output will be counter=5 counter=4 counter=3 counter=2 counter=1 10/27/15 [email protected]
  • 63. Break • This will help to exit from the loop when a certain condition is met.Here break is a keyword in Python. • Ex: j=0 for I in the range(5): j=j+2 print(‘i=‘,i, ‘j=‘,j) if j==6: break 10/27/15 [email protected]
  • 64. contd.. • The output of the above program will be: i=0,j=2 i=1,j=4 i=2,j=6 without the break keyword ,the program should loop from i=0 to i=4 because the function range(5) is used. Due to the keyword break ,the program ends early at i=2.Because when i=2 ,j reaches the value 6 . 10/27/15 [email protected]
  • 65. Continue • Continue is another important keyword for Loops. • When the keyword continue is used ,the rest of the loop after the keyword is skipped for that iteration. • Ex: j=0 for i in range (5): j=j+2 print(‘ni=‘,I,j=‘,j) if j==6: continue 10/27/15 [email protected]
  • 66. contd.. • Print(‘i will be skipped over if j=6’) The output of the program is as below: i=0,j=2 I will be skipped over if j=6 i=1,j=4 I will be skipped over if j=6 i=2,j=6 i=3,j=8 i= 4,j=10 I will be skipped over if j=6 When j=6,the line after the continue keyword is not printed. 10/27/15 [email protected]
  • 67. Try,Except • This control statement controls how the program proceeds when an error occurs The syntax is as below. • Try: do a Task except do something else when an error occurs 10/27/15 [email protected]
  • 68. contd.. • For Ex: try: answer = 50/0 print(answer) except: print(‘An error occurred’) when we run the program,the message “An error occurred” will be displayed because answer=50/0 in the try block canot divide a num,ber by 0.So,the remaining of the try block is ignored and the statement in the except block is executed. 10/27/15 [email protected]
  • 69. Functions-Modules • Functions are pre-written codes that perform a dedicated task. • For ex: the function sum() add the numbers. • Some function require us to pass data in for them to perform their task.These data are known as parameters and we pass them to the function by enclosing their values in parenthesis() separated by commas. • The print() function is used to display the text on the screen. 10/27/15 [email protected]
  • 70. contd.. • replace() is another function used for manipulating the text strings. • For Ex: “helloworld”.replace(“world”,”Universe”) here “world” and “universe” are the parameters.The string before the Dot is the string that will be affected.So,”hello world” will be changed to “hello Universe” 10/27/15 [email protected]
  • 71. Your own Functions • Python has has flexibility to define your own functions and can be used them in the program. • The syntax is: def functionName(parameters): code for what the function should do return[expression] The two keywords here are “def” and “return” 10/27/15 [email protected]
  • 72. contd.. • def tells the program that the indented code from the next line onwards is part of the function and return is the keyword that is used to return an answer from the function. • Once the function executes a return statement ,it will exit. • If your function need not return any value you can write return or return None. 10/27/15 [email protected]
  • 73. contd.. • Ex:def checkIfPrime(numberToCheck): for x in range(2,numberToCheck): if(numberToCheck%x==0); return False return True The above function will check whether the given number is a prime number or not.If the number is not a prime number it will return False otherwise return True. 10/27/15 [email protected]
  • 74. Variable Scope • An important concept to understand while defining a function is the concept of variable scope. • Variables defined inside a function are treated differently from variables defined outside. • Any variable defined inside a function is only accessible within the function and such functions are known as local variables. • Any variable declared outside a function is known as global variable and it is accessible anywhere in the program. 10/27/15 [email protected]
  • 75. Importing Modules • Python provides a large number of built-in functions and these are saved in files known as modules. • To use the modules in our program ,first we have to import them into our programs. and this is done by using the keyword import. Ex: To import the module random we write import random 10/27/15 [email protected]
  • 76. contd.. • To use the randrange() function in the random module we use random.randrange(1,10). This can also be written as r.randrange(1,10). • If we want to import more than one functions we separate them with a comma • To import the randrange() and randint() functions we write from random import randrange,randint. 10/27/15 [email protected]
  • 77. Creating own Module • Creating a module is simple and it can be done by saving the file with a .py extension and put it in the same folder as the python file that you are going to import it from. • Suppose you want to use the checkIfPrime()function defined earlier in another Python script.First save the code above as prime.ph on your desktop. 10/27/15 [email protected]
  • 78. contd.. • The prime.py should have the following code. def checkIfPrime(numberToCheck): for x in range(2,numberToCheck): if(numberToCheck%x==0): return False return True Next create another python file and name it useCheckIfPrime.py This should have the following code 10/27/15 [email protected]
  • 79. contd.. • Import prime answer = prime.checkIfPrime(17) print(answer) • Now run useCheckIfPrime.py. • You get the output as True • Suppose you want to store prime.py and useCheckIfPrime.py in different folders, you have to give the python’s system path. 10/27/15 [email protected]
  • 80. contd.. • Create a folder called ‘MyPythonModules’ in the C drive to store prime.py. • Add the following code to the top of your useCheckIfPrime.py file. (i.e before the import prime line) • Import sys if’C:MyPythonModules’not in sys.path: sys.path.append(‘C:MyPythonModules’) here sys.path refers to python’s system path. 10/27/15 [email protected]
  • 81. contd.. • The code above appends the folder’C:MyPythonModules’ to your system path. • Now you can put prime.py in C:MyPythonModules and checkIfPrime.py in any other folder of your choice. 10/27/15 [email protected]
  • 82. Handling Files • The basic type of a file is a text file.It consists of multiple lines of text.To create a text file type some lines of text like “I am learning Python programming. Python is an interesting language” . save this text file as myfile.txt on your desktop. Next open Idle and type the code below. 10/27/15 [email protected]
  • 83. contd.. • f= open(‘myfile.txt’,’r’) firstline=f.readline() secondline=f.readline() print(firstline) print(secondline) f.close() Save this code as fileOperation.py on your desktop. • To open a file we can use open() function. 10/27/15 [email protected]
  • 84. contd.. • The open function require two parameters:The first one is the path to the file and the second parameter is the mode. • The commonly used modes are • ‘r’mode: For reading only • ‘w’mode: For writing only. • ‘a’ mode: For appending .If the specified file does not exist ,it will be created and if the file exist ,any data written to the file is automatically added at the end of the file. 10/27/15 [email protected]
  • 85. contd.. • ‘r+’mode:For both reading and writing. • After opening the file firstline=f.readline() reads the firstline in the file and assigns it to the variable firstline. Each time the readline() function is called ,it reads a new line from the file. When you run the program the output will be I am learning Python programming. Python is an interesting language. 10/27/15 [email protected]
  • 86. contd.. • In the output ,you can observe that a line break is inserted after each line. • Because the function readline() adds the ‘n’ characters to the end of each line. • If you don’t want the extra line between each line of text ,you can wrte print(firstline,end=‘’).This will remove the ‘n’ characters • f.close() function closes the file.One should always close the file after reading is done.It will freeup any system resources. 10/27/15 [email protected]
  • 87. For Loop to Read Text Files • For loop can also be used to read a text file. • For ex: f = open(‘myfile.txt’,’r’) for line in f: print(line,end=‘’) f.close() The for loop helps to read the text file line by line. 10/27/15 [email protected]
  • 88. Opening and reading Text files by Buffer size • To avoid the too much usage of memory we can use the read() function instead of readline() function. • Ex: msg=inputfile.read(10) The program reads only the next 19 bytes and keeps doing it until the entire file is read. 10/27/15 [email protected]
  • 89. Deleting and re-naming the Files • remove() and rename() are the two important functions available as modules which have to be imported before they are used in a program. • The remove() function deletes a file.the syntax is remove(filename) • Ex: remove(‘myfile.txt’) • To rename a file the function rename() is used. • The syntax is rename(old name,new name) • rename(‘oldfile.txt,’newfile.txt’) will rename oldfile.txt to newfile.txt 10/27/15 [email protected]
  • 90. Simple Examples-1 • Python code to find the area of a triangle: • First open Idle and type the code • a = float(input(‘Enter first side:’)) b= float(input(‘Enter first side:’)) c= float(input(‘Enter first side:’)) s=(a+b+c)/2 area=(s*(s-a)*(s-b)*(s-c))**0.5 print(‘The area of the triangle is %0.2f’%area) 10/27/15 [email protected]
  • 91. Simple Examples-2 • Python code to find Square root num=float(input(‘Enter a number:’)) num_sqrt=num**0.5 print(‘The square root of %0.3f is % 0.3f% (num,num_sqrt)) This program is saved with .py extension and executed .the out will ask to enter a number and on entering a number it gives the squre root of the number. 10/27/15 [email protected]
  • 92. Simple Examples-3 • Python code for factorial of a number • Num= int(input(‘Enter a number:’)) factorial = 1 if num < 0: print(‘sorry ,factorial does not exist for negative numbers’) elif num == 0; print(“The factorial of 0 is 1”) 10/27/15 [email protected]
  • 93. contd.. • else for i in range(1,num+1): factorial = factorial*i print(“The factorial of “,num,”is”,factorial) • Save the program with .py extension and run module or press F5. • The program will ask to enter a number • After entering the number you get the output 10/27/15 [email protected]
  • 94. Simple Examples-4 • Print all the Prime numbers in an Interval. • Lower=int(input(‘Enter lower range:’)) upper=int(input(‘Enter upper range)) for num in range(lower,upper+1): if num>1: for i in range(2,num): if(num%i)==0: break else: print(num) 10/27/15 [email protected]
  • 95. Simple Examples-5 • Code to swap two numbers • x= input(‘Enter value of x:’) y=input(‘Enter value of y:’) temp = x x=y y= temp print(‘The value of x after swapping: { }’format(x)) print(‘The value of y after swapping: { }’format(y)). Run the code and observe the output 10/27/15 [email protected]
  • 96. Simple Examples-6 • Solve a quadratic equation ax2+bx+c=0 • Import cmath # add complex math module a= float(input(‘Enter a:’)) b= float(input(‘Enter b:’)) c= float(input(‘Enter c:’)) d= (b**2)-(4*a*c) //calculate discriminant sol1=(-b-cmath.sqrt(d))/(2*a) sol2=(-b+cmath.sqrt(d))/(2*a) print(‘The solutions are {0} and {1}.format(sol1,sol2)) 10/27/15 [email protected]
  • 97. Simple Examples-7 • To find ASCII value of a given characters • # Take character from user c = input("Enter a character: ") print("The ASCII value of '" + c + "' is",ord(c)) Note: here ord(c) is a builtin function available in Python to find the ASCII value of a character 10/27/15 [email protected]
  • 98. ACKNOWLEDGEMENT • I don’t claim any ownership for this lecture as it is the collection from many books &web resources • I thank the authors of the books and web resources from where I collected the information and code. • The sole objective behind this effort is only to encourage and inspire if possible some young minds towards this wonderful programming language -Python 10/27/15 [email protected]
  • 99. References • Learn Python in One Day and Learn It Well - Jamie Chan. • Sams Teach Yourself Python Programming for Raspberry. • Programming Python, 5th Edition,O'Reilly Media. • Python Cook Book O'Reilly Media. 10/27/15 [email protected]

IMAGES

  1. Python_Seminar.ppt

    presentation on python programming

  2. PPT

    presentation on python programming

  3. PPT

    presentation on python programming

  4. PPT

    presentation on python programming

  5. Python Programming ppt

    presentation on python programming

  6. PPT

    presentation on python programming

VIDEO

  1. Presentation python in library system for book storage

  2. Overview of Python Programming

  3. Python Project Presentation 👩‍💻 #python #programming #chuechuevlogs

  4. Introduction to Python Programming and Its Application L Intro

  5. Python Tutorial 1: Introduction

  6. 1.Python Programming: An Introduction for Beginners

COMMENTS

  1. Lecture Slides and Code

    Find the slides and code from each lecture of Introduction to Computer Science and Programming in Python, a course offered by MIT OpenCourseWare. Learn the basics of Python, data structures, algorithms, and object-oriented programming.

  2. Free PPT Slides for Python Programming

    Introduction To Python Programming. Python Programming (58 Slides) 93715 Views. Unlock a Vast Repository of Python Programming PPT Slides, Meticulously Curated by Our Expert Tutors and Institutes. Download Free and Enhance Your Learning!

  3. Fundamentals of Python Programming

    1. Fundamentals of Python Programming. 2. Introduction to python programming • High level, interpreted language • Object-oriented • General purpose • Web development (like: Django and Bottle), • Scientific and mathematical computing (Orange, SciPy, NumPy) • Desktop graphical user Interfaces (Pygame, Panda3D). 3.

  4. PDF Introduction to Programming with Python

    2 code or source code: The sequence of instructions in a program. syntax: The set of legal structures and commands that can be used in a particular programming language. output: The messages printed to the user by a program. console: The text box onto which output is printed. Some source code editors pop up the console as an external window,

  5. Zero to Hero

    90. Python3: Zero to Hero - Introduction to Python Programming 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 documentation string of the function or docstring. statement return [expression] exits a function ...

  6. Explore Python fundamentals

    Explore Python fundamentals. Python is a general purpose programming language that can be used for both programming and scripting. It was created in the 1990s by Guido van Rossum who named it after the Monty Python comedy troupe. People use Python for a variety of tasks due to its readability, object-oriented capabilities, extensive libraries ...

  7. Slides

    Part I. Fundamental Python Programming Part I. Fundamental Python Programming Chapter 1: Introduction Chapter 1: Introduction Introduction Python Crash Course Chapter 2: Variable and Expression Chapter 2: Variable and Expression Variables ... Presentation Slides ...

  8. Introduction to Python Programming

    Module 1 • 8 hours to complete. This first module covers an intro to programming and the Python language. We'll start by downloading and installing the necessary tools to begin programming and writing code in Python. After learning how to print to the console, we'll get an understanding of Python's basic data types, and how to do simple ...

  9. Introduction To Python Programming

    Introduction To Python Programming. Python is widely used general-purpose, high-level 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.

  10. Presentation Slides

    340.3 KB. Download Presentation Slides: Module 1 3.8 MB Download Presentation Slides: Module 2 1013.6 KB Download Presentation Slides: Module 3 507.3 KB Download Presentation Slides: Module 4 772.3 KB Download Presentation Slides: Module 5 788.9 KB Download….

  11. Introduction to Python

    Learn what Python is, what it can do, and why it is a popular programming language. This tutorial covers the basics of Python syntax, features, and applications with examples and exercises.

  12. Introduction to Python Programming.ppt

    Page 3 of 46. Background Data Types/Structure Control flow File I/O Modules Class NLTK

  13. PPT

    Origin of Python • Python is a general-purpose interpreted, interactive, object-oriented, and high-level programming language. It was created by Guido van Rossum during 1985- 1990. • Python is designed to be highly readable. It uses English keywords frequently where as other languages use punctuation.

  14. introduction to Python (for beginners)

    introduction to Python (for beginners) Mar 11, 2020 • Download as PPTX, PDF •. 1 like • 398 views. G. guobichrng. 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 ...

  15. Programming Python Code PowerPoint Presentation and Slides

    Presenting Programming Python Code In Powerpoint And Google Slides Cpb slide which is completely adaptable. The graphics in this PowerPoint slide showcase four stages that will help you succinctly convey the information. In addition, you can alternate the color, font size, font type, and shapes of this PPT layout according to your content.

  16. Presenting Python code using RISE

    1. Write the python code/logic for the presentation. Let's write the logic of "find the largest number in a Python list". The logic for this will be really minimalistic and easy to understand. Let's use the below-given algorithm to write the logic: Create a list of values. Sort the list using sort().

  17. Free templates about Programming for Google Slides & PPT

    Programming Lesson. If you teach programming languages and related issues, download and personalize this template to prepare your lesson. The fonts look computer-like, and it's very creative. Insert some info about the features of the topic, assignments and support them with visual aids, such as bar graphs. Technology.

  18. Creating Presentations with Python

    python-pptx is a Python library for creating and updating PowerPoint files. This article is going to be a basic introduction to this package. If you want to learn much more about it, this is the official documentation page that you should check. Now let's install the package if you don't have. pip install python-pptx.

  19. Python overview: What is it and its key features

    Python is an interpreted, object-oriented programming language created by Guido van Rossum in 1990. It has a clear, readable syntax and is designed to be highly extensible. Python code is often much shorter than equivalent code in other languages like C++ or Java due to features like indentation-based blocks and dynamic typing.

  20. Creating Powerpoint Presentations with Python

    Here is the start of the function that we use to create our output PowerPoint: def create_ppt(input, output, report_data, chart): """ Take the input powerpoint file and use it as the template for the output file. """ prs = Presentation(input) # Use the output from analyze_ppt to understand which layouts and placeholders # to use # Create a ...

  21. Introduction to Python

    Introduction to Python. Sep 11, 2010 • Download as PPT, PDF •. 400 likes • 168,829 views. Nowell Strite. Introduction to Python slides from the Vermont Code Camp 2010 gathering. Technology. 1 of 64. Download now. Introduction to Python - Download as a PDF or view online for free.

  22. Creating and updating PowerPoint Presentations in Python using python

    pip install python-pptx. Let's see some of its usage: Example 1: Creating new PowerPoint file with title and subtitle slide. Python3. from pptx import Presentation . root = Presentation() first_slide_layout = root.slide_layouts[0] . 0 -> title and subtitle. 5 -> Title only .

  23. Python Programming Language

    7. contd.. • Python can be used for large variety of tasks like Desktop applications ,Data base applications,network programming ,game programming and even mobile development also. • Python is also a cross platform language which means that the code written for one operating system like Windows ,will work equally well with Linux or MacOS without any changes to the python code. 10/27/15 ...