Python Overview and getting started in Python Language. It includes on how to install, run it and carrying out some simple python codes in different environments(IDLEs)
Python 101++: Let's Get Down to Business!Paige Bailey
You've started the Codecademy and Coursera courses; you've thumbed through Zed Shaw's "Learn Python the Hard Way"; and now you're itching to see what Python can help you do. This is the workshop for you!
Here's the breakdown: we're going to be taking you on a whirlwind tour of Python's capabilities. By the end of the workshop, you should be able to easily follow any of the widely available Python courses on the internet, and have a grasp on some of the more complex aspects of the language.
Please don't forget to bring your personal laptop!
Audience: This course is aimed at those who already have some basic programming experience, either in Python or in another high level programming language (such as C/C++, Fortran, Java, Ruby, Perl, or Visual Basic). If you're an absolute beginner -- new to Python, and new to programming in general -- make sure to check out the "Python 101" workshop!
Introduction to the basics of Python programming (part 3)Pedro Rodrigues
This is the 3rd part of a multi-part series that teaches the basics of Python programming. It covers list and dict comprehensions, functions, modules and packages.
The basics of Python are rather straightforward. In a few minutes you can learn most of the syntax. There are some gotchas along the way that might appear tricky. This talk is meant to bring programmers up to speed with Python. They should be able to read and write Python.
The core of extensible programming is defining functions. Python allows mandatory and optional arguments, keyword arguments, and even arbitrary argument lists
Python is a high-level, interpreted programming language that is designed to be easy to read and write. It has a clear syntax using English keywords and its code is often shorter than languages like C++ and Java. Python is widely used for web development, software development, science, and machine learning. It has a large standard library and can be extended through modules. Some key data structures in Python include lists, tuples, and dictionaries.
Basics of python with suitable examples (data types, loops (if, else, elif, while, for) , functions and its types and a program in python used for ordering the numbers)
Python 101++: Let's Get Down to Business!Paige Bailey
You've started the Codecademy and Coursera courses; you've thumbed through Zed Shaw's "Learn Python the Hard Way"; and now you're itching to see what Python can help you do. This is the workshop for you!
Here's the breakdown: we're going to be taking you on a whirlwind tour of Python's capabilities. By the end of the workshop, you should be able to easily follow any of the widely available Python courses on the internet, and have a grasp on some of the more complex aspects of the language.
Please don't forget to bring your personal laptop!
Audience: This course is aimed at those who already have some basic programming experience, either in Python or in another high level programming language (such as C/C++, Fortran, Java, Ruby, Perl, or Visual Basic). If you're an absolute beginner -- new to Python, and new to programming in general -- make sure to check out the "Python 101" workshop!
Introduction to the basics of Python programming (part 3)Pedro Rodrigues
This is the 3rd part of a multi-part series that teaches the basics of Python programming. It covers list and dict comprehensions, functions, modules and packages.
The basics of Python are rather straightforward. In a few minutes you can learn most of the syntax. There are some gotchas along the way that might appear tricky. This talk is meant to bring programmers up to speed with Python. They should be able to read and write Python.
The core of extensible programming is defining functions. Python allows mandatory and optional arguments, keyword arguments, and even arbitrary argument lists
Python is a high-level, interpreted programming language that is designed to be easy to read and write. It has a clear syntax using English keywords and its code is often shorter than languages like C++ and Java. Python is widely used for web development, software development, science, and machine learning. It has a large standard library and can be extended through modules. Some key data structures in Python include lists, tuples, and dictionaries.
Basics of python with suitable examples (data types, loops (if, else, elif, while, for) , functions and its types and a program in python used for ordering the numbers)
Python supports multiple programming paradigms, including object-oriented, imperative and functional programming or procedural styles. It features a dynamic type system and automatic memory management and has a large and comprehensive standard library.
A slightly modified version of original "An introduction to Python
for absolute beginners" slides. For credits please check the second page. I used this presentation for my company's internal Python course.
This document provides an overview of functions and file handling in Python. It discusses defining user-defined functions with the def keyword, including passing arguments, default arguments, keyword arguments, and variable number of arguments. It also covers recursion, anonymous functions, and attributes of file objects. For file handling, it explains opening, reading, writing, and appending files, as well as the different file modes.
Python Workshop - Learn Python the Hard WayUtkarsh Sengar
This document provides an introduction to learning Python. It discusses prerequisites for Python, basic Python concepts like variables, data types, operators, conditionals and loops. It also covers functions, files, classes and exceptions handling in Python. The document demonstrates these concepts through examples and exercises learners to practice char frequency counting and Caesar cipher encoding/decoding in Python. It encourages learners to practice more to master the language and provides additional learning resources.
The document discusses various Python datatypes. It explains that Python supports built-in and user-defined datatypes. The main built-in datatypes are None, numeric, sequence, set and mapping types. Numeric types include int, float and complex. Common sequence types are str, bytes, list, tuple and range. Sets can be created using set and frozenset datatypes. Mapping types represent a group of key-value pairs like dictionaries.
The document discusses file input and output in Python. It covers opening files, reading the entire file or line by line, writing to files, and closing files. It also covers if/elif/else conditional statements, comparison operators, and examples of problems and solutions involving file I/O and conditional logic.
This presentation covers Python most important data structures like Lists, Dictionaries, Sets and Tuples. Exception Handling and Random number generation using simple python module "random" also covered. Added simple python programs at the end of the presentation
This document provides an introduction to the Python language and discusses Python data types. It covers how to install Python, interact with the Python interpreter through command line and IDLE modes, and learn basic Python parts like data types, operators, functions, and control structures. The document discusses numeric, string, and other data types in Python and how to manipulate them using built-in functions and operators. It also introduces Python library modules and the arcpy package for geoprocessing in ArcGIS.
This document provides an agenda and overview for a Python training course. The agenda covers key Python topics like dictionaries, conditional statements, loops, functions, modules, input/output, error handling, object-oriented programming and more. The introduction section explains that Python is an interpreted, interactive and object-oriented language well-suited for beginners. It also outlines features like rapid development, automatic memory management and support for procedural and object-oriented programming. The document concludes by explaining Python's core data types including numbers, strings, lists, tuples and dictionaries.
This document provides an overview of the Python programming language. It discusses what Python is, its key features like being multi-purpose, readable, and productive. It then demonstrates Hello World programs in Python, C++, Java, and PHP. The rest of the document covers Python concepts like operators, variables, strings, lists, conditions, loops, functions, object oriented programming, and design patterns like strategy, closure, generator, and decorator patterns.
The document provides an overview of Python lists:
- Lists allow you to store sets of information in a particular order and are one of Python's most powerful features.
- You can define lists using square brackets and commas, and use plural names for lists to make code more readable. Lists can contain millions of items.
- Lists allow adding, inserting, removing, sorting, and accessing elements by their position or value using various list methods like append(), insert(), remove(), sort(), and indexing.
- Loops like for loops efficiently iterate through lists to work with each element.
This document provides an introduction to the Python programming language. It discusses what Python is, its history and creator, why it is popular, who uses it, and how to get started with the syntax. Key topics covered include Python's readability, dynamic typing, standard library, and use across many industries. The document also includes code examples demonstrating basic Python concepts like variables, strings, control flow, functions, and file input/output.
Introduction to the Python programming language (version 2.x)
Ambient intelligence: technology and design
http://bit.ly/polito-ami
Politecnico di Torino, 2015
The document provides an introduction to programming in Python. It discusses how Python can be used for web development, desktop applications, data science, machine learning, and more. It also covers executing Python programs, reading keyboard input, decision making and loops in Python, standard data types like numbers, strings, lists, tuples and dictionaries. Additionally, it describes functions, opening and reading/writing files, regular expressions, and provides examples of SQLite database connections in Python projects.
Python is a versatile, object-oriented programming language that can be used for web development, data analysis, and more. It has a simple syntax and is easy to read and learn. Key features include being interpreted, dynamically typed, supporting functional and object-oriented programming. Common data types include numbers, strings, lists, dictionaries, tuples, and files. Functions and classes can be defined to organize and reuse code. Regular expressions provide powerful string manipulation. Python has a large standard library and is used widely in areas like GUIs, web scripting, AI, and scientific computing.
Functions, Exception, Modules and Files
Functions: Difference between a Function and a Method, Defining a Function, Calling a Function, Returning Results from a Function, Returning Multiple Values from a Function, Functions are First Class Objects, Pass by Object Reference, Formal and Actual Arguments, Positional Arguments, Keyword Arguments, Default Arguments, Variable Length Arguments, Local and Global Variables, The Global Keyword, Passing a Group of Elements to a Function, Recursive Functions, Anonymous Functions or Lambdas (Using Lambdas with filter() Function, Using Lambdas with map() Function, Using Lambdas with reduce() Function), Function Decorators, Generators, Structured Programming, Creating our Own Modules in Python, The Special Variable __name__
Exceptions: Errors in a Python Program (Compile-Time Errors, Runtime Errors, Logical Errors),Exceptions, Exception Handling, Types of Exceptions, The Except Block, The assert Statement, UserDefined Exceptions, Logging the Exceptions
20%
Files: Files, Types of Files in Python, Opening a File, Closing a File, Working with Text Files Containing Strings, Knowing Whether a File Exists or Not, Working with Binary Files, The with Statement, Pickle in Python, The seek() and tell() Methods, Random Accessing of Binary Files, Random Accessing of Binary Files using mmap, Zipping and Unzipping Files, Working with Directories, Running Other Programs from Python Program
mooc_presentataion_mayankmanral on the subject puthongarvitbisht27
Python prr ppt hai so plzz nsjsiskbdbdjdjdkdjdndndndndmmdmdndndndndndndndnndndndnndndndmememdmsjakksmwbshskammanahaialemneeuislmeheuiekememejkeksmwjejekekmemenejekmemrme
Python supports multiple programming paradigms, including object-oriented, imperative and functional programming or procedural styles. It features a dynamic type system and automatic memory management and has a large and comprehensive standard library.
A slightly modified version of original "An introduction to Python
for absolute beginners" slides. For credits please check the second page. I used this presentation for my company's internal Python course.
This document provides an overview of functions and file handling in Python. It discusses defining user-defined functions with the def keyword, including passing arguments, default arguments, keyword arguments, and variable number of arguments. It also covers recursion, anonymous functions, and attributes of file objects. For file handling, it explains opening, reading, writing, and appending files, as well as the different file modes.
Python Workshop - Learn Python the Hard WayUtkarsh Sengar
This document provides an introduction to learning Python. It discusses prerequisites for Python, basic Python concepts like variables, data types, operators, conditionals and loops. It also covers functions, files, classes and exceptions handling in Python. The document demonstrates these concepts through examples and exercises learners to practice char frequency counting and Caesar cipher encoding/decoding in Python. It encourages learners to practice more to master the language and provides additional learning resources.
The document discusses various Python datatypes. It explains that Python supports built-in and user-defined datatypes. The main built-in datatypes are None, numeric, sequence, set and mapping types. Numeric types include int, float and complex. Common sequence types are str, bytes, list, tuple and range. Sets can be created using set and frozenset datatypes. Mapping types represent a group of key-value pairs like dictionaries.
The document discusses file input and output in Python. It covers opening files, reading the entire file or line by line, writing to files, and closing files. It also covers if/elif/else conditional statements, comparison operators, and examples of problems and solutions involving file I/O and conditional logic.
This presentation covers Python most important data structures like Lists, Dictionaries, Sets and Tuples. Exception Handling and Random number generation using simple python module "random" also covered. Added simple python programs at the end of the presentation
This document provides an introduction to the Python language and discusses Python data types. It covers how to install Python, interact with the Python interpreter through command line and IDLE modes, and learn basic Python parts like data types, operators, functions, and control structures. The document discusses numeric, string, and other data types in Python and how to manipulate them using built-in functions and operators. It also introduces Python library modules and the arcpy package for geoprocessing in ArcGIS.
This document provides an agenda and overview for a Python training course. The agenda covers key Python topics like dictionaries, conditional statements, loops, functions, modules, input/output, error handling, object-oriented programming and more. The introduction section explains that Python is an interpreted, interactive and object-oriented language well-suited for beginners. It also outlines features like rapid development, automatic memory management and support for procedural and object-oriented programming. The document concludes by explaining Python's core data types including numbers, strings, lists, tuples and dictionaries.
This document provides an overview of the Python programming language. It discusses what Python is, its key features like being multi-purpose, readable, and productive. It then demonstrates Hello World programs in Python, C++, Java, and PHP. The rest of the document covers Python concepts like operators, variables, strings, lists, conditions, loops, functions, object oriented programming, and design patterns like strategy, closure, generator, and decorator patterns.
The document provides an overview of Python lists:
- Lists allow you to store sets of information in a particular order and are one of Python's most powerful features.
- You can define lists using square brackets and commas, and use plural names for lists to make code more readable. Lists can contain millions of items.
- Lists allow adding, inserting, removing, sorting, and accessing elements by their position or value using various list methods like append(), insert(), remove(), sort(), and indexing.
- Loops like for loops efficiently iterate through lists to work with each element.
This document provides an introduction to the Python programming language. It discusses what Python is, its history and creator, why it is popular, who uses it, and how to get started with the syntax. Key topics covered include Python's readability, dynamic typing, standard library, and use across many industries. The document also includes code examples demonstrating basic Python concepts like variables, strings, control flow, functions, and file input/output.
Introduction to the Python programming language (version 2.x)
Ambient intelligence: technology and design
http://bit.ly/polito-ami
Politecnico di Torino, 2015
The document provides an introduction to programming in Python. It discusses how Python can be used for web development, desktop applications, data science, machine learning, and more. It also covers executing Python programs, reading keyboard input, decision making and loops in Python, standard data types like numbers, strings, lists, tuples and dictionaries. Additionally, it describes functions, opening and reading/writing files, regular expressions, and provides examples of SQLite database connections in Python projects.
Python is a versatile, object-oriented programming language that can be used for web development, data analysis, and more. It has a simple syntax and is easy to read and learn. Key features include being interpreted, dynamically typed, supporting functional and object-oriented programming. Common data types include numbers, strings, lists, dictionaries, tuples, and files. Functions and classes can be defined to organize and reuse code. Regular expressions provide powerful string manipulation. Python has a large standard library and is used widely in areas like GUIs, web scripting, AI, and scientific computing.
Functions, Exception, Modules and Files
Functions: Difference between a Function and a Method, Defining a Function, Calling a Function, Returning Results from a Function, Returning Multiple Values from a Function, Functions are First Class Objects, Pass by Object Reference, Formal and Actual Arguments, Positional Arguments, Keyword Arguments, Default Arguments, Variable Length Arguments, Local and Global Variables, The Global Keyword, Passing a Group of Elements to a Function, Recursive Functions, Anonymous Functions or Lambdas (Using Lambdas with filter() Function, Using Lambdas with map() Function, Using Lambdas with reduce() Function), Function Decorators, Generators, Structured Programming, Creating our Own Modules in Python, The Special Variable __name__
Exceptions: Errors in a Python Program (Compile-Time Errors, Runtime Errors, Logical Errors),Exceptions, Exception Handling, Types of Exceptions, The Except Block, The assert Statement, UserDefined Exceptions, Logging the Exceptions
20%
Files: Files, Types of Files in Python, Opening a File, Closing a File, Working with Text Files Containing Strings, Knowing Whether a File Exists or Not, Working with Binary Files, The with Statement, Pickle in Python, The seek() and tell() Methods, Random Accessing of Binary Files, Random Accessing of Binary Files using mmap, Zipping and Unzipping Files, Working with Directories, Running Other Programs from Python Program
mooc_presentataion_mayankmanral on the subject puthongarvitbisht27
Python prr ppt hai so plzz nsjsiskbdbdjdjdkdjdndndndndmmdmdndndndndndndndnndndndnndndndmememdmsjakksmwbshskammanahaialemneeuislmeheuiekememejkeksmwjejekekmemenejekmemrme
This document provides an overview of the Python programming language. It discusses Python's history and design, data types like integers, floats, strings, lists, tuples and dictionaries. It also covers core concepts like variables, expressions, control flow with if/else statements and loops. The document demonstrates how to take user input, read and write files, and describes moving Python code to files to make it reusable.
This document provides an overview of learning Python in three hours. It covers Python's history, installing and running Python, basic data types like integers, floats and strings. It also discusses sequence types like lists, tuples and strings, and how lists are mutable while tuples are immutable. The document includes examples of basic syntax like assignment, conditionals, functions and modules. It provides guidance on naming conventions and discusses the Python interpreter, editors and development environments.
This document provides an overview of the Python programming language. It discusses Python's history, how to install and run Python, basic data types like integers, floats, strings, lists and tuples. It also covers topics like functions, modules, files, and classes in Python.
This document provides an overview of the Python programming language. It discusses Python's history and key features such as being an interpreted, object-oriented, and functional language. The document also covers installing Python, running Python scripts and programs, basic datatypes like integers and strings, sequence types like lists and tuples, and other basic concepts like functions, variables, and flow control.
The document provides an overview of the Python programming language. It discusses Python's history, how to install and run Python, basic data types like integers, floats, strings, lists and tuples. It explains key concepts like variable assignment, conditional statements, functions, modules and packages. The document also compares mutable lists and immutable tuples, and covers common list operations.
The document provides an overview of the Python programming language. It discusses Python's history, how to install and run Python, basic data types like integers, floats, strings, lists and tuples. It explains key concepts like variable assignment, basic operations, slicing of sequences, and how lists are mutable but tuples are immutable. The document is intended to teach Python fundamentals in about three hours.
This document provides an overview of the Python programming language. It discusses Python's history and key features such as being object-oriented, scalable, and functional from the beginning. It also covers installing Python, running Python programs, basic datatypes like integers and strings, sequence types like lists and tuples, and other basic concepts like functions, comments, and whitespace.
The document provides an overview of the Python programming language. It discusses Python's history, how to install and run Python, basic data types like integers, floats, strings, lists and tuples. It explains key concepts like variable assignment, basic operations, slicing of sequences, and how lists are mutable but tuples are immutable. The document is intended to teach Python fundamentals in about three hours.
The document provides an overview of the Python programming language. It discusses Python's history, how to install and run Python, basic data types like integers, floats, strings, lists and tuples. It explains key concepts like variable assignment, basic operations, slicing of sequences, and how lists are mutable but tuples are immutable. The document is intended to teach Python fundamentals in about three hours.
The document provides an overview of the Python programming language. It discusses Python's history, how to install and run Python, basic data types like integers, floats, strings, lists and tuples. It explains key concepts like variable assignment, conditional statements, functions, modules and packages. The document also compares mutable lists and immutable tuples, and covers common list operations.
The document provides an overview of the Python programming language. It discusses Python's history, how to install and run Python, basic data types like integers, floats, strings, lists and tuples. It explains key concepts like variable assignment, conditional statements, functions, modules and packages. The document also compares mutable lists and immutable tuples, and covers common list operations.
This document provides an overview of the Python programming language. It discusses Python's history and key features such as being an interpreted, object-oriented, and functional language. The document also covers installing Python, running Python scripts and programs, basic datatypes like integers and strings, sequence types like lists and tuples, and other basic concepts like functions, variables, and flow control.
The document provides an overview of the Python programming language. It discusses Python's history, how to install and run Python, basic data types like integers, floats, strings, lists and tuples. It explains key concepts like variable assignment, basic operations, slicing of sequences, and how lists are mutable but tuples are immutable. The document is intended to teach Python fundamentals in about three hours.
The document provides an overview of the Python programming language. It discusses Python's history, how to install and run Python, basic data types like integers, floats, strings, and lists. It also covers Python concepts like functions, modules, conditionals, loops, classes and objects.
The document provides an overview of the Python programming language. It discusses Python's history and key features such as being scalable, object oriented, and functional. It also covers installing Python, running Python programs, basic datatypes like integers and strings, sequence types like lists and tuples, and other basic concepts like functions, variables, and control flow.
The document provides an overview of the Python programming language. It discusses Python's history, how to install and run Python, basic data types like integers, floats, strings, lists and tuples. It explains key Python concepts like variable assignment, conditional statements, functions, modules and packages. The document also compares mutable lists and immutable tuples, and covers common list operations.
This document provides a summary of Week 2 of a Python programming course. It discusses dictionaries, including defining, modifying, and deleting dictionary items. It also covers lists, such as defining and slicing lists, as well as adding, searching, and deleting list elements. Finally, it introduces tuples as immutable lists and discusses variable declaration and string formatting in Python.
Similar to Getting started in Python presentation by Laban K (20)
How Can Hiring A Mobile App Development Company Help Your Business Grow?ToXSL Technologies
ToXSL Technologies is an award-winning Mobile App Development Company in Dubai that helps businesses reshape their digital possibilities with custom app services. As a top app development company in Dubai, we offer highly engaging iOS & Android app solutions. https://rb.gy/necdnt
E-commerce Development Services- Hornet DynamicsHornet Dynamics
For any business hoping to succeed in the digital age, having a strong online presence is crucial. We offer Ecommerce Development Services that are customized according to your business requirements and client preferences, enabling you to create a dynamic, safe, and user-friendly online store.
UI5con 2024 - Bring Your Own Design SystemPeter Muessig
How do you combine the OpenUI5/SAPUI5 programming model with a design system that makes its controls available as Web Components? Since OpenUI5/SAPUI5 1.120, the framework supports the integration of any Web Components. This makes it possible, for example, to natively embed own Web Components of your design system which are created with Stencil. The integration embeds the Web Components in a way that they can be used naturally in XMLViews, like with standard UI5 controls, and can be bound with data binding. Learn how you can also make use of the Web Components base class in OpenUI5/SAPUI5 to also integrate your Web Components and get inspired by the solution to generate a custom UI5 library providing the Web Components control wrappers for the native ones.
Most important New features of Oracle 23c for DBAs and Developers. You can get more idea from my youtube channel video from https://youtu.be/XvL5WtaC20A
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfVALiNTRY360
Salesforce Healthcare CRM, implemented by VALiNTRY360, revolutionizes patient management by enhancing patient engagement, streamlining administrative processes, and improving care coordination. Its advanced analytics, robust security, and seamless integration with telehealth services ensure that healthcare providers can deliver personalized, efficient, and secure patient care. By automating routine tasks and providing actionable insights, Salesforce Healthcare CRM enables healthcare providers to focus on delivering high-quality care, leading to better patient outcomes and higher satisfaction. VALiNTRY360's expertise ensures a tailored solution that meets the unique needs of any healthcare practice, from small clinics to large hospital systems.
For more info visit us https://valintry360.com/solutions/health-life-sciences
Unveiling the Advantages of Agile Software Development.pdfbrainerhub1
Learn about Agile Software Development's advantages. Simplify your workflow to spur quicker innovation. Jump right in! We have also discussed the advantages.
Flutter is a popular open source, cross-platform framework developed by Google. In this webinar we'll explore Flutter and its architecture, delve into the Flutter Embedder and Flutter’s Dart language, discover how to leverage Flutter for embedded device development, learn about Automotive Grade Linux (AGL) and its consortium and understand the rationale behind AGL's choice of Flutter for next-gen IVI systems. Don’t miss this opportunity to discover whether Flutter is right for your project.
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsPeter Muessig
The UI5 tooling is the development and build tooling of UI5. It is built in a modular and extensible way so that it can be easily extended by your needs. This session will showcase various tooling extensions which can boost your development experience by far so that you can really work offline, transpile your code in your project to use even newer versions of EcmaScript (than 2022 which is supported right now by the UI5 tooling), consume any npm package of your choice in your project, using different kind of proxies, and even stitching UI5 projects during development together to mimic your target environment.
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...kalichargn70th171
In today's business landscape, digital integration is ubiquitous, demanding swift innovation as a necessity rather than a luxury. In a fiercely competitive market with heightened customer expectations, the timely launch of flawless digital products is crucial for both acquisition and retention—any delay risks ceding market share to competitors.
14 th Edition of International conference on computer visionShulagnaSarkar2
About the event
14th Edition of International conference on computer vision
Computer conferences organized by ScienceFather group. ScienceFather takes the privilege to invite speakers participants students delegates and exhibitors from across the globe to its International Conference on computer conferences to be held in the Various Beautiful cites of the world. computer conferences are a discussion of common Inventions-related issues and additionally trade information share proof thoughts and insight into advanced developments in the science inventions service system. New technology may create many materials and devices with a vast range of applications such as in Science medicine electronics biomaterials energy production and consumer products.
Nomination are Open!! Don't Miss it
Visit: computer.scifat.com
Award Nomination: https://x-i.me/ishnom
Conference Submission: https://x-i.me/anicon
For Enquiry: Computer@scifat.com
3. Brief History of Python
•Invented in the Netherlands, early 90s by Guido van
Rossum
•Named after Monty Python
•Open sourced from the beginning
•Considered a scripting language, but is much more
•Scalable, object oriented and functional from the
beginning
•Used by Google from the beginning
•Increasingly popular
7. The Python Interpreter
•Typical Python implementations offer
both an interpreter and compiler
•Interactive interface to Python with a
read-eval-print loop
9. IDLE Development Environment
• IDLE is an Integrated DeveLopment Environ-ment
for Python, typically used on Windows
• Multi-window text editor with syntax highlighting,
auto-completion, smart indent and other.
• Python shell with syntax highlighting.
• Integrated debugger
with stepping, persis-
tent breakpoints,
and call stack visi-
bility
10. Python Scripts
•When you call a python program from the command
line the interpreter evaluates each expression in the
file
•Familiar mechanisms are used to provide command
line arguments and/or redirect input and output
•Python also has mechanisms to allow a python
program to act both as a script and as a module to be
imported and used by another python program
11. A Code Sample (in IDLE)
x = 34 - 23 # A comment.
y = “Hello” # Another one.
z = 3.45
if z == 3.45 or y == “Hello”:
x = x + 1
y = y + “ World” # String concat.
print x
print y
12. Enough to Understand the Code
•Indentation matters to code meaning
• Block structure indicated by indentation
•First assignment to a variable creates it
• Variable types don’t need to be declared.
• Python figures out the variable types on its own.
•Assignment is = and comparison is ==
•For numbers + - * / % are as expected
• Special use of + for string concatenation and %
for string formatting (as in C’s printf)
•Logical operators are words (and, or, not) not
symbols
•The basic printing command is print
13. Basic Datatypes
•Integers (default for numbers)
z = 5 / 2 # Answer 2, integer division
•Floats
x = 3.456
•Strings
•Can use “” or ‘’ to specify with “abc” == ‘abc’
•Unmatched can occur within the string: “matt’s”
•Use triple double-quotes for multi-line strings or
strings than contain both ‘ and “ inside of them:
“““a‘b“c”””
14. Comments
• Start comments with #, rest of line is ignored
• Can include a “documentation string” as the first
line of a new function or class you define
• Development environments, debugger, and other
tools use it: it’s good style to include one
def fact(n):
“““fact(n) assumes n is a positive integer and returns
facorial of n.”””
assert(n>0)
return 1 if n==1 else n*fact(n-1)
15. Reserved Words
•Names are case sensitive and cannot start with a
number. They can contain letters, numbers, and
underscores.
bob Bob _bob _2_bob_ bob_2 BoB
•There are some reserved words:
and, assert, break, class, continue, def, del, elif, else,
except, exec, finally, for, from, global, if, import, in, is,
lambda, not, or, pass, print, raise, return, try, while
16. Assignment
• You can assign to multiple names at the same
time
>>> x, y = 2, 3
>>> x
2
>>> y
3
This makes it easy to swap values
>>> x, y = y, x
• Assignments can be chained
>>> a = b = x = 2
18. Sequence Types
1. Tuple: (‘john’, 32, [CMSC])
A simple immutable ordered sequence of items
Items can be of mixed types, including
collection types
2. Strings: “John Smith”
• Immutable
• Conceptually very much like a tuple
3. List: [1, 2, ‘john’, (‘up’, ‘down’)]
Mutable ordered sequence of items of mixed
types
19. The ‘in’ Operator
• Boolean test whether a value is inside a container:
>>> t = [1, 2, 4, 5]
>>> 3 in t
False
>>> 4 in t
True
>>> 4 not in t
False
• For strings, tests for substrings
>>> a = 'abcde'
>>> 'c' in a
True
>>> 'cd' in a
True
>>> 'ac' in a
False
• Be careful: the in keyword is also used in the syntax of for loops and list
comprehensions
20. The + Operator
The + operator produces a new tuple, list, or string
whose value is the concatenation of its arguments.
>>> (1, 2, 3) + (4, 5, 6)
(1, 2, 3, 4, 5, 6)
>>> [1, 2, 3] + [4, 5, 6]
[1, 2, 3, 4, 5, 6]
>>> “Hello” + “ ” + “World”
‘Hello World’
21. The * Operator
•The * operator produces a new tuple, list, or string
that “repeats” the original content.
>>> (1, 2, 3) * 3
(1, 2, 3, 1, 2, 3, 1, 2, 3)
>>> [1, 2, 3] * 3
[1, 2, 3, 1, 2, 3, 1, 2, 3]
>>> “Hello” * 3
‘HelloHelloHello’
23. Lists are mutable
>>> li = [‘abc’, 23, 4.34, 23]
>>> li[1] = 45
>>> li
[‘abc’, 45, 4.34, 23]
•We can change lists in place.
•Name li still points to the same memory
reference when we’re done.
24. Tuples are immutable
>>> t = (23, ‘abc’, 4.56, (2,3), ‘def’)
>>> t[2] = 3.14
Traceback (most recent call last):
File "<pyshell#75>", line 1, in -toplevel-
tu[2] = 3.14
TypeError: object doesn't support item assignment
• You can’t change a tuple.
• You can make a fresh tuple and assign its reference to a
previously used name.
>>> t = (23, ‘abc’, 3.14, (2,3), ‘def’)
• The immutability of tuples means they’re faster than
lists.
25. Operations on Lists Only
>>> li = [1, 11, 3, 4, 5]
>>> li.append(‘a’) # Note the method syntax
>>> li
[1, 11, 3, 4, 5, ‘a’]
>>> li.insert(2, ‘i’)
>>>li
[1, 11, ‘i’, 3, 4, 5, ‘a’]
26. The extend method vs +
• + creates a fresh list with a new memory ref
• extend operates on list li in place.
>>> li.extend([9, 8, 7])
>>> li
[1, 2, ‘i’, 3, 4, 5, ‘a’, 9, 8, 7]
• Potentially confusing:
• extend takes a list as an argument.
• append takes a singleton as an argument.
>>> li.append([10, 11, 12])
>>> li
[1, 2, ‘i’, 3, 4, 5, ‘a’, 9, 8, 7, [10, 11, 12]]
27. Operations on Lists Only
Lists have many methods, including index, count,
remove, reverse, sort
>>> li = [‘a’, ‘b’, ‘c’, ‘b’]
>>> li.index(‘b’) # index of 1st occurrence
1
>>> li.count(‘b’) # number of occurrences
2
>>> li.remove(‘b’) # remove 1st occurrence
>>> li
[‘a’, ‘c’, ‘b’]
28. Operations on Lists Only
>>> li = [5, 2, 6, 8]
>>> li.reverse() # reverse the list *in place*
>>> li
[8, 6, 2, 5]
>>> li.sort() # sort the list *in place*
>>> li
[2, 5, 6, 8]
>>> li.sort(some_function)
# sort in place using user-defined comparison
29. Tuple details
• The comma is the tuple creation operator, not parens
>>> 1,
(1,)
• Python shows parens for clarity (best practice)
>>> (1,)
(1,)
• Don't forget the comma!
>>> (1)
1
• Trailing comma only required for singletons others
• Empty tuples have a special syntactic form
>>> ()
()
>>> tuple()
()
30. Summary: Tuples vs. Lists
•Lists slower but more powerful than tuples
•Lists can be modified, and they have lots of handy
operations and mehtods
•Tuples are immutable and have fewer features
•To convert between tuples and lists use the list() and
tuple() functions:
li = list(tu)
tu = tuple(li)