By Austin Laudenslager AN INTRODUCTION TO PYTHON.

Slides:



Advertisements
Similar presentations
For loops Genome 559: Introduction to Statistical and Computational Genomics Prof. James H. Thomas.
Advertisements

String and Lists Dr. Benito Mendoza. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list List.
Title An Introduction to Python. What is Python exactly? Python is a modern rapid development language. Code is very clean and easy to read. Emphasizes.
Introduction to Python. Outline Python IS ……. History Installation Data Structures Flow of Control Functions Modules References.
Introduction to Python
Intro to Python Paul Martin. History Designed by Guido van Rossum Goal: “Combine remarkable power with very clear syntax” Very popular in science labs.
CSCI/CMPE 4341 Topic: Programming in Python Chapter 3: Control Structures (Part 1) – Exercises 1 Xiang Lian The University of Texas – Pan American Edinburg,
JaySummet IPRE Python Review 2. 2 Outline Compound Data Types: Strings, Tuples, Lists & Dictionaries Immutable types: Strings Tuples Accessing.
Introduction to Python (for C++ programmers). Background Information History – created in December 1989 by Guido van Rossum Interpreted Dynamically-typed.
Python Programming Fundamentals
Introduction to Python Lecture 1. CS 484 – Artificial Intelligence2 Big Picture Language Features Python is interpreted Not compiled Object-oriented language.
Introduction to Python Guido van Rossum Director of PythonLabs at Zope Corporation
COMPUTER SCIENCE FEBRUARY 2011 Lists in Python. Introduction to Lists Lists (aka arrays): an ordered set of elements  A compound data type, like strings.
COMPE 111 Introduction to Computer Engineering Programming in Python Atılım University
October 4, 2005ICP: Chapter 4: For Loops, Strings, and Tuples 1 Introduction to Computer Programming Chapter 4: For Loops, Strings, and Tuples Michael.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 9 More About Strings.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Built-in Data Structures in Python An Introduction.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 8 Working.
With Python.  One of the most useful abilities of programming is the ability to manipulate files.  Python’s operations for file management are relatively.
Introducing Python CS 4320, SPRING Resources We will be following the Python tutorialPython tutorial These notes will cover the following sections.
Python uses boolean variables to evaluate conditions. The boolean values True and False are returned when an expression is compared or evaluated.
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 8 Lists and Tuples.
More about Strings. String Formatting  So far we have used comma separators to print messages  This is fine until our messages become quite complex:
Introduction to Strings Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg 1.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
Jim Havrilla. Invoking Python Just type “python –m script.py [arg]” or “python –c command [arg]” To exit, quit() or Control-D is used To just use the.
Python Let’s get started!.
Python Mini-Course University of Oklahoma Department of Psychology Day 3 – Lesson 11 Using strings and sequences 5/02/09 Python Mini-Course: Day 3 – Lesson.
More Sequences. Review: String Sequences  Strings are sequences of characters so we can: Use an index to refer to an individual character: Use slices.
CS190/295 Programming in Python for Life Sciences: Lecture 6 Instructor: Xiaohui Xie University of California, Irvine.
LISTS and TUPLES. Topics Sequences Introduction to Lists List Slicing Finding Items in Lists with the in Operator List Methods and Useful Built-in Functions.
Introduction to Computing Using Python Repetition: the for loop  Execution control structures  for loop – iterating over a sequence  range() function.
Introduction to Python Sajal Desai. What is Python? Versitile, simple, high level language No linking and compilation “By the way, the language is named.
Python Arithmetic Operators OperatorOperationDescription +AdditionAdd values on either side of the operator -SubtractionSubtract right hand operand from.
Introduction to Programming Oliver Hawkins. BACKGROUND TO PROGRAMMING LANGUAGES Introduction to Programming.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
String and Lists Dr. José M. Reyes Álamo. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list.
Mr. Crone.  Use print() to print to the terminal window  print() is equivalent to println() in Java Example) print(“Hello1”) print(“Hello2”) # Prints:
String and Lists Dr. José M. Reyes Álamo.
G. Pullaiah College of Engineering and Technology
Tuples and Lists.
CS-104 Final Exam Review Victor Norman.
Python is a general-purpose interpreted, interactive, object-oriented, and high-level programming language. It was created by Guido van Rossum during.
Introduction to Strings
Introduction to Strings
Introduction To Python
Lists in Python.
An Introduction to Python
CS190/295 Programming in Python for Life Sciences: Lecture 6
T. Jumana Abu Shmais – AOU - Riyadh
3 Control Statements:.
String and Lists Dr. José M. Reyes Álamo.
Python Tutorial for C Programmer Boontee Kruatrachue Kritawan Siriboon
Topics Sequences Introduction to Lists List Slicing
Introduction to Strings
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Topics Basic String Operations String Slicing
Topics Sequences Introduction to Lists List Slicing
Introduction to Strings
Python Review
Topics Basic String Operations String Slicing
Comparing Python and Java
Class code for pythonroom.com cchsp2cs
Introduction to Strings
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Topics Basic String Operations String Slicing
Tuple.
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

By Austin Laudenslager AN INTRODUCTION TO PYTHON

 Created in 1989 by Guido van Rossum  Highly extensible  Aims to create beautiful, readable code  Variables are assigned a type automatically  Blocks of code are defined by whitespace  Arguments from the console are stored in the argv variable, which can be accessed using sys.argv[n]  _ variable can be used in interactive mode to refer to the previous expression – it can not be assigned a value manually PYTHON

 +, -, *, % work the same as C++/Java  / returns a float, // performs integer division  ** can be used to calculate powers  Use parenthesis for grouping () MATH TIP: Integers and floating point numbers may both be used in the same equation without typecasting, computes to floating point number. >>>5+5>>>5*5>>>7% >>>5/2>>>5// >>>5**2>>>10** >>>5*2+2>>>5*(2+2) 1220

 Can be enclosed in either single or double quotes  \ can be used to escape quotes, \n is new line  Use print() to display strings, r ignores special characters  Triple quotes allows strings to span multiple lines STRINGS >>> ‘string’ >>> “string” >>>’I can\’t’>>>’Line one\nLine two’ ‘I can’t”Line one Line two >>>Print(‘some\name’)>>>print(r’some\name’) somesome\name ame >>>print(“”” Line one Line two “””) Line one Line two

 + allows for concatenation, * performs repetition  Strings are indexed from the left AND right  Use [n:m] to slice strings  Use len() to return the length of a string STRING OPERATIONS >>> ‘string’ + ‘one’>>> ‘string’ * 3 ‘stringone’‘stringstringstring’ >>>word=‘Python’>>>word[0]>>>word[-2] ‘P’‘0’ >>>word[2:4]>>>word[:2] ‘th’‘Py’ >>>len(word) 6 TIP: Strings are immutable: Word[3] = ‘z’ will NOT work.

 Declared as a list of comma seperated values  Can be indexed, sliced, and concatenated the same as strings  ARE mutable, can be changed by index OR slice  Can use function append() to add items to the end of a list  Funtion len() returns length of list  Can nest lists: LISTS >>>numbers = [1, 2, 3]>>>strings = [‘a’, ‘b’, ‘c’] >>>number.append(1)>>>len(number) [4, 8, 7, 3, 1]5 >>>nest = [numbers, words] >>>nest[0]>>>nest[0][3] [4, 8, 7, 3, 1]3 >>>numbers[1] = 5>>>numbers[0:2] = [4, 8, 7] [1, 5, 3][4, 8, 7, 3]

 While, if, elif, else work like in C++  Unlike C++, for loops iterate over items of a sequence numbers = [6, 2, 4]  Use range(n) to iterate over a sequence of number  Break statement ends current loop  Else can also be used with loops  Continue statement skips to the next iteration of the loop  Pass can be used to represent a statement where no action is needed CONTROL FLOW STATEMENTS >>>for n in numbers: TIP: Control flow statements do NOT use parenthesis in Python. >>>for i in range(10) IMPORTANT: Python uses whitespace indentation, levels of code are determined by indentation, not grouped by curly braces!

 All functions are of the def, or definition type  Can return any type of object  Returns none by default  Example function:  n can be of any type and will be returned as the same type  Can also include optional arguments with default values:  Can be called with multiply(n) or multiply(n,m) FUNCTIONS >>> def returnVal(n): print(n) return n >>> def multiply(n, count=2): return n*count

SOURCES ng_language%29