Python. Karin Lagesen.
|
|
- Ellen Holt
- 5 years ago
- Views:
Transcription
1 Python Karin Lagesen
2 Plan for the day Basic data types data manipulation Flow control and file handling Functions Biopython package
3 What is programming? Programming: ordered set of instructions Programming can be compared to a: Cooking recipe Ikea furniture instructions Lab protocol Language: instruction set Programming: combining instructions to solve problem
4 How to make a program Need a programming language Programming language dictates the set of available instructions Several types of languages several types of instruction sets Two main types: Interpreted languages Compiled languages
5 Interpreted languages No compilation needed Program interpreted on-the-fly Programs often called scripts Example of interpreted languages: General purpose: perl, python Special purpose: R Possible disadvantage: can be slower than compiled programs.
6 Interactive vs. batch mode Python can be used in the shell, interactively Useful for testing etc Exit from python: Ctrl-D Most common: save code in text file, run in shell Called batch mode
7 Python data types Numbers: integers and floats Strings Lists Dictionaries Not taught today: sets and tuples
8 Two different type features Sequence datatypes: Sequential order Strings, lists and tuples Immutable datatypes: Cannot be changed Numbers, strings, tuples
9 Exercise in class Log in to freebee.abel.uio.no Create a directory called python Type in module load python2 Type in python You are now in the python interactive shell
10 Python operators
11 Python as a calculator Do the following: *23 12/6 11/6 11.0/6 2**8
12 Python as a calculator [karinlag@freebee]~/teaching% python Python (default, Jun , 15:54:55) [GCC (Red Hat )] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> >>> >>> 5* >>> 12/6 2 >>> 11/6 1 >>> 11.0/ >>> 2**8 256 >>> In python 2x, division rounds numbers down
13 Creating script A script is code in a file which is run Create script file: Open nano Write in print 2+2 Save the file as first.py Run script: python first.py Modify: add other calculations
14 first.py cat first.py print 2+2 print 4 2 print 3*6 print 7**8 [karinlag@freebee]~/teaching% [karinlag@freebee]~/teaching% python first.py [karinlag@freebee]~/teaching%
15 Strings Use ', or ''' to delineate Remember: same type on each end ''' can be used to create block text >>> '''This is a piece... of block text''' 'This is a piece\nof block text' >>> Newline: \n Tab: \t
16 String operations >>> "TTAAGAGGA".replace("T", "U") 'UUAAGAGGA' >>> "TTAAGAGGA".count("G") 3 >>> "TTAAGAGGA".find("AG") 3 >>> "TTAAGAGGA".find("AGX") 1 >>> "TTAAGAGGA".index("AG") 3 >>> "TTAAGAGGA".index("AGX") Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: substring not found >>> "TTAAGAGGA".split("A") ['TT', '', 'G', 'GG', ''] >>> "TTA,AGA,GGA".split(",") ['TTA', 'AGA', 'GGA'] >>> "TTA AGA GGA".split() ['TTA', 'AGA', 'GGA'] >>> Note the error message! This is pythons way of telling you something went wrong. Repeat on freebee
17 Variables A variable is something that has a value that may change Naming variables: Letters, numbers and _ CasE sensitive Numbers may not be first Some words are reserved Convention: small letters, underscore to separate words
18 Reserved words
19 Using variables >>> t1 = "TTAAGAGGA" >>> t2 = "GGGG" >>> t1 + t2 'TTAAGAGGAGGGG' >>> t1.replace("t", "U") 'UUAAGAGGA' >>> t1 'TTAAGAGGA' >>> t3 = t1.replace("t", "U") >>> t3 'UUAAGAGGA' >>> We are using the variable instead of the string itself Can do the same thing to another string
20 count.py Create script file: Open nano Write in text = "ATGGCGGAGGA" nogs = text.count("g") print text, "contains", nogs, "Gs" Save the file Run script: python count.py Modify: count GGs instead of Gs
21 Dynamic, strong typing Type in the following: >>> t1 = "TTAAGAGGA" >>> t4 = 123 >>> t1 + t4 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: cannot concatenate 'str' and 'int' objects >>> No need to specify type Type is interpreted as we go along python objects we do something wrong
22 Lists Ordered collection of elements list1 = [elem, elem, elem] Can hold elements of any type, including another list >>> list1 = ["a", "c", b ] >>> list2 = ["X", "Y", list1] >>> list2 ['X', 'Y', ['a', 'c', 'b']] Can be sorted (in place) using.sort() >>> list1.sort() >>> list1 ['a', 'b', 'c'] >>>
23 Adding to list Create empty list: list1 = [] Add to list: list1.append(elem) Adds element to the end Extend list: list1.extend(elem) Extends list with elements
24 List adding example >>> list1 = "A,B,C,D,E".split(",") >>> list1 ['A', 'B', 'C', 'D', 'E'] >>> list1.append('f') >>> list1 ['A', 'B', 'C', 'D', 'E', 'F'] >>> list1.extend('g') >>> list1 ['A', 'B', 'C', 'D', 'E', 'F', 'G'] >>> list1.insert(3,'g') >>> list1 ['A', 'B', 'C', 'G', 'D', 'E', 'F', 'G'] >>> list1.extend([1,2]) >>> list1 ['A', 'B', 'C', 'G', 'D', 'E', 'F', 'G', 1, 2] >>> list1.append([1,2]) ` Basic adding to list Note difference between append and extend! >>> list1 ['A', 'B', 'C', 'G', 'D', 'E', 'F', 'G', 1, 2, [1, 2]] >>>
25 List removal list1.remove(elem) remove specified element list1.pop(index) return elem in index, default is last
26 Special list: sys.argv How do you get input from command line? Example: calculate AT content for a text that you give the script Everything after script name on command line is in list called sys.argv [karinlag@freebee]~/teaching% cat sys_argv.py import sys print sys.argv [karinlag@freebee]~/teaching% python sys_argv.py a b c ['sys_argv.py', 'a', 'b', 'c'] [karinlag@freebee]~/teaching% python sys_argv.py 1 2 ['sys_argv.py', '1', '2'] [karinlag@freebee]~/teaching% To use: import sys on top
27 Sequence methods Works on strings, lists and tuples Indexing Index starts at zero Negative indices go from right edge Slicing Can access portions of sequence using indices In operator test for membership Concatenation add two together with + Len, min, max
28 Indices >>> text = "ABCDEFG" >>> text[2] 'C' >>> text[ 2] 'F' >>> text[2:4] 'CD' >>> text[2: 2] 'CDE' >>> text[:4] 'ABCD' >>> text[4:] 'EFG' >>> A B C D E F G Note: for slicing, it is [from and including : to but excluding]
29 in operator Test if element is in sequence Works with lists, sequences, tuples >>> X = [1,4,8,2,9] >>> X [1, 4, 8, 2, 9] >>> 5 in X False >>> 8 in X True >>> >>> X = "ABCDEF" >>> X 'ABCDEF' >>> "Y" in X False >>> >>> "BC" in X True >>>
30 Concatenation Concatenation: + sign Can only concatenate same types >>> a = [1,2] >>> b = [3,4] >>> a + b [1, 2, 3, 4] >>> c = 56 >>> a + c Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: can only concatenate list (not "int") to list >>> Canging types is called casting: Change string to number: int(string), float(string) Change number to string: str(number)
31 Len, min, max Len: length of sequence object Min: minimum Max: maximum >>> txt1 = "ABCDEF" >>> len(txt1) 6 >>> max(txt1) 'F' >>> min(txt1) 'A' >>>
32 Sequence manipulation In python interactive shell: Create list [1,4,8,2,10] Find the maximum number Find out if the number 9 is in the list Add the number 9 to the list, repeat test Use sort to find the two lowest numbers All, except sort, works for strings too!
33 Sequence manipulation >>> list1 = [1,4,8,2,10] >>> list1 [1, 4, 8, 2, 10] >>> max(list1) 10 >>> 9 in list1 False >>> list1.append(9) >>> list1 [1, 4, 8, 2, 10, 9] >>> 9 in list1 True >>> list1.sort() >>> list1 [1, 2, 4, 8, 9, 10] >>> list1[:2] [1, 2] >>> Max in list Is 9 in list? Define list Add 9 to list Retest for 9 Sort list Get two lowest numbers
34 atcontent.py Create script file: Text is ATGGCCGG, read in as sys.argv[1] Figure out: Run script: Length Number of As Number of Ts python atcontent.py ATGGCCGG Modify: how do you figure out AT content?
35 atcontent.py cat atcontent.py import sys text = sys.argv[1] As = text.count("a") Ts = text.count("t") print "Length of", text, "is", len(text) print "Nos of As is", As print "Nos of Ts is", Ts print "AT content is", (As + Ts)*1.0/len(text) [karinlag@freebee]~/teaching% % python atcontent.py ATGGCGG Length of ATGGCCGG is 8 Nos of As is 1 Nos of Ts is 1 AT content is 0.25 [karinlag@freebee]~/teaching%
36 Dictionaries Stores unordered, arbitrarily indexed data Consists of key-value pairs Dict = {key:value, key:value, key:value...} Note: keys must be immutable! ergo: numbers, tuples or strings Values may be anything, incl. another dictionary Mainly used for storing associations or mappings
37 Create, add, lookup, remove Creation: mydict = {} (empty), or mydict = { mykey:myval, mykey2:myval2 } Adding: mydict[key] = value Lookup: mydict[key] Remove: del mydict[key]
38 Dictionary methods All keys: mylist.keys() - returns list of keys All values: mydict.values() - returns list of values All key-value pairs as list of tuples: mydict.items() Get one specific value: mydict.get(key [, default]) if default is given, that is returned if key is not present in the dictionary, else None is returned Test for presence of key: key in mydict returns True or False
39 dict_manip.py Create script file: Create this dictionary: { A : 1, 1: A, B :[1,2,3]} Find out the following: Run script: how many pairs are there? add str : {1: X } to the dictionary print the value that is stored with key str python dict_manip.py Modify: print the last element from the list stored under B
40 dict_manip.py cat dict_manip.py my_dict = {"A": 1, 1:"A", "B":[1,2,3]} print "Nos of elements", len(my_dict) my_dict["str"] = {1:"X"} print "my_dict['str']", my_dict["str"] print "last element in list with key 'B'", my_dict["b"][ 1] [karinlag@freebee]~/teaching% [karinlag@freebee]~/teaching% python dict_manip.py Nos of elements 3 my_dict['str'] {1: 'X'} last element in list with key 'B' 3 [karinlag@freebee]~/teaching%
Interactive use. $ python. >>> print 'Hello, world!' Hello, world! >>> 3 $ Ctrl-D
1/60 Interactive use $ python Python 2.7.5 (default, Mar 9 2014, 22:15:05) [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin Type "help", "copyright", "credits" or "license" for more information.
More informationInteractive use. $ python. >>> print 'Hello, world!' Hello, world! >>> 3 $ Ctrl-D
1/58 Interactive use $ python Python 2.7.5 (default, Mar 9 2014, 22:15:05) [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin Type "help", "copyright", "credits" or "license" for more information.
More informationBasic Python Revision Notes With help from Nitish Mittal
Basic Python Revision Notes With help from Nitish Mittal HELP from Documentation dir(module) help() Important Characters and Sets of Characters tab \t new line \n backslash \\ string " " or ' ' docstring
More information18.1. CS 102 Unit 18. Python. Mark Redekopp
18.1 CS 102 Unit 18 Python Mark Redekopp 18.2 Credits Many of the examples below are taken from the online Python tutorial at: http://docs.python.org/tutorial/introduction.html 18.3 Python in Context Two
More informationSome material adapted from Upenn cmpe391 slides and other sources
Some material adapted from Upenn cmpe391 slides and other sources History Installing & Running Python Names & Assignment Sequences types: Lists, Tuples, and Strings Mutability Understanding Reference Semantics
More informationCollections. Lists, Tuples, Sets, Dictionaries
Collections Lists, Tuples, Sets, Dictionaries Homework notes Homework 1 grades on canvas People mostly lost points for not reading the document carefully Didn t play again Didn t use Y/N for playing again
More informationData Structures. Lists, Tuples, Sets, Dictionaries
Data Structures Lists, Tuples, Sets, Dictionaries Collections Programs work with simple values: integers, floats, booleans, strings Often, however, we need to work with collections of values (customers,
More informationPython Intro GIS Week 1. Jake K. Carr
GIS 5222 Week 1 Why Python It s simple and easy to learn It s free - open source! It s cross platform IT S expandable!! Why Python: Example Consider having to convert 1,000 shapefiles into feature classes
More informationPython allows variables to hold string values, just like any other type (Boolean, int, float). So, the following assignment statements are valid:
1 STRINGS Objectives: How text data is internally represented as a string Accessing individual characters by a positive or negative index String slices Operations on strings: concatenation, comparison,
More informationPython for Non-programmers
Python for Non-programmers A Gentle Introduction 2 Yann Tambouret Scientific Computing and Visualization Information Services & Technology Boston University 111 Cummington St. yannpaul@bu.edu Winter 2013
More informationPython for Non-programmers
Python for Non-programmers A Gentle Introduction 1 Yann Tambouret Scientific Computing and Visualization Information Services & Technology Boston University 111 Cummington St. yannpaul@bu.edu Winter 2013
More informationThe current topic: Python. Announcements. Python. Python
The current topic: Python Announcements! Introduction! reasons for studying languages! language classifications! simple syntax specification Object-oriented programming: Python Types and values Syntax
More informationComputer Sciences 368 Scripting for CHTC Day 3: Collections Suggested reading: Learning Python
Day 3: Collections Suggested reading: Learning Python (3rd Ed.) Chapter 8: Lists and Dictionaries Chapter 9: Tuples, Files, and Everything Else Chapter 13: while and for Loops 1 Turn In Homework 2 Homework
More informationCourse Introduction and Python Basics
Course Introduction and Python Basics Johan Falkenjack 2018-01-15 Course Introduction Python > Data Science 3 hp pass/fail 3 lectures, 3 labs (2 sessions for each lab) Python Basics Programming Paradigms
More informationPython I. Some material adapted from Upenn cmpe391 slides and other sources
Python I Some material adapted from Upenn cmpe391 slides and other sources Overview Names & Assignment Data types Sequences types: Lists, Tuples, and Strings Mutability Understanding Reference Semantics
More informationThere are four numeric types: 1. Integers, represented as a 32 bit (or longer) quantity. Digits sequences (possibly) signed are integer literals:
Numeric Types There are four numeric types: 1. Integers, represented as a 32 bit (or longer) quantity. Digits sequences (possibly) signed are integer literals: 1-123 +456 2. Long integers, of unlimited
More informationIntroduction to Python
Introduction to Python Jon Kerr Nilsen, Dmytro Karpenko Research Infrastructure Services Group, Department for Research Computing, USIT, UiO Why Python Clean and easy-to-understand syntax alldata = cpickle.load(open(filename1,
More informationPython. Executive Summary
Python Executive Summary DEFINITIONS OBJECT: a unit of data of a particular type with characteristic functionality (i.e., methods and/or response to operators). Everything in Python is an object. "atomic"
More informationChapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.
Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of
More informationTypes, lists & functions
Week 2 Types, lists & functions Data types If you want to write a program that allows the user to input something, you can use the command input: name = input (" What is your name? ") print (" Hello "+
More informationLab 6: Data Types, Mutability, Sorting. Ling 1330/2330: Computational Linguistics Na-Rae Han
Lab 6: Data Types, Mutability, Sorting Ling 1330/2330: Computational Linguistics Na-Rae Han Objectives Data types and conversion Tuple Mutability Sorting: additional parameters Text processing overview
More informationLesson 4: Type Conversion, Mutability, Sequence Indexing. Fundamentals of Text Processing for Linguists Na-Rae Han
Lesson 4: Type Conversion, Mutability, Sequence Indexing Fundamentals of Text Processing for Linguists Na-Rae Han Objectives Python data types Mutable vs. immutable object types How variable assignment
More informationScript language: Python Data structures
Script language: Python Data structures Cédric Saule Technische Fakultät Universität Bielefeld 3. Februar 2015 Immutable vs. Mutable Previously known types: int and string. Both are Immutable but what
More information\n is used in a string to indicate the newline character. An expression produces data. The simplest expression
Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of
More informationProgramming in Python
3. Sequences: Strings, Tuples, Lists 15.10.2009 Comments and hello.py hello.py # Our code examples are starting to get larger. # I will display "real" programs like this, not as a # dialog with the Python
More informationSTA141C: Big Data & High Performance Statistical Computing
STA141C: Big Data & High Performance Statistical Computing Lecture 1: Python programming (1) Cho-Jui Hsieh UC Davis April 4, 2017 Python Python is a scripting language: Non-scripting language (C++. java):
More informationHistory Installing & Running Python Names & Assignment Sequences types: Lists, Tuples, and Strings Mutability
History Installing & Running Python Names & Assignment Sequences types: Lists, Tuples, and Strings Mutability Some material adapted from Upenn cmpe391 slides and other sources Invented in the Netherlands,
More information06/11/2014. Subjects. CS Applied Robotics Lab Gerardo Carmona :: makeroboticsprojects.com June / ) Beginning with Python
CS95003 - Applied Robotics Lab Gerardo Carmona :: makeroboticsprojects.com June / 2014 Subjects 1) Beginning with Python 2) Variables 3) Strings 4) Basic arithmetic operators 5) Flow control 6) Comparison
More informationPython and Bioinformatics. Pierre Parutto
Python and Bioinformatics Pierre Parutto October 9, 2016 Contents 1 Common Data Structures 2 1.1 Sequences............................... 2 1.1.1 Manipulating Sequences................... 2 1.1.2 String.............................
More informationIntroduction to Python
Introduction to Python Development Environments what IDE to use? 1. PyDev with Eclipse 2. Sublime Text Editor 3. Emacs 4. Vim 5. Atom 6. Gedit 7. Idle 8. PIDA (Linux)(VIM Based) 9. NotePad++ (Windows)
More informationTEXT MINING INTRO TO PYTHON
TEXT MINING INTRO TO PYTHON Johan Falkenjack (based on slides by Mattias Villani) NLPLAB Dept. of Computer and Information Science Linköping University JOHAN FALKENJACK (NLPLAB, LIU) TEXT MINING 1 / 23
More informationLISTS WITH PYTHON. José M. Garrido Department of Computer Science. May College of Computing and Software Engineering Kennesaw State University
LISTS WITH PYTHON José M. Garrido Department of Computer Science May 2015 College of Computing and Software Engineering Kennesaw State University c 2015, J. M. Garrido Lists with Python 2 Lists with Python
More informationIntroduction to Python
Introduction to Python Reading assignment: Perkovic text, Ch. 1 and 2.1-2.5 Python Python is an interactive language. Java or C++: compile, run Also, a main function or method Python: type expressions
More informationCS1110 Lab 1 (Jan 27-28, 2015)
CS1110 Lab 1 (Jan 27-28, 2015) First Name: Last Name: NetID: Completing this lab assignment is very important and you must have a CS 1110 course consultant tell CMS that you did the work. (Correctness
More informationShell scripting and system variables. HORT Lecture 5 Instructor: Kranthi Varala
Shell scripting and system variables HORT 59000 Lecture 5 Instructor: Kranthi Varala Text editors Programs built to assist creation and manipulation of text files, typically scripts. nano : easy-to-learn,
More informationSenthil Kumaran S
Senthil Kumaran S http://www.stylesen.org/ Agenda History Basics Control Flow Functions Modules History What is Python? Python is a general purpose, object-oriented, high level, interpreted language Created
More informationCS Programming Languages: Python
CS 3101-1 - Programming Languages: Python Lecture 5: Exceptions / Daniel Bauer (bauer@cs.columbia.edu) October 08 2014 Daniel Bauer CS3101-1 Python - 05 - Exceptions / 1/35 Contents Exceptions Daniel Bauer
More informationCS 1110 SPRING 2016: GETTING STARTED (Jan 27-28) First Name: Last Name: NetID:
CS 1110 SPRING 2016: GETTING STARTED (Jan 27-28) http://www.cs.cornell.edu/courses/cs1110/2016sp/labs/lab01/lab01.pdf First Name: Last Name: NetID: Goals. Learning a computer language is a lot like learning
More informationPython Class-Lesson1 Instructor: Yao
Python Class-Lesson1 Instructor: Yao What is Python? Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. Its high-level built in data structures, combined
More informationMEIN 50010: Python Strings
: Python Strings Fabian Sievers Higgins Lab, Conway Institute University College Dublin Wednesday, 2017-10-25 Lecture Basic string manipulation Converting between different variable types strings Command-line
More informationIntroduction to Python
Introduction to Python CB2-101 Introduction to Scientific Computing November 11 th, 2014 Emidio Capriotti http://biofold.org/emidio Division of Informatics Department of Pathology Python Python high-level
More informationCOMP519 Web Programming Lecture 17: Python (Part 1) Handouts
COMP519 Web Programming Lecture 17: Python (Part 1) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool Contents
More informationAn Introduction to Python
An Introduction to Python Day 2 Renaud Dessalles dessalles@ucla.edu Python s Data Structures - Lists * Lists can store lots of information. * The data doesn t have to all be the same type! (unlike many
More informationLists How lists are like strings
Lists How lists are like strings A Python list is a new type. Lists allow many of the same operations as strings. (See the table in Section 4.6 of the Python Standard Library Reference for operations supported
More informationProgramming to Python
Programming to Python Sept., 5 th Slides by M. Stepp, M. Goldstein, M. DiRamio, and S. Shah Compiling and interpreting Many languages require you to compile (translate) your program into a form that the
More informationCOLLEGE OF ENGINEERING, NASHIK-4
Pune Vidyarthi Griha s COLLEGE OF ENGINEERING, NASHIK-4 DEPARTMENT OF COMPUTER ENGINEERING Important PYTHON Questions 1. What is Python? Python is a high-level, interpreted, interactive and object-oriented
More informationTable of Contents EVALUATION COPY
Table of Contents Introduction... 1-2 A Brief History of Python... 1-3 Python Versions... 1-4 Installing Python... 1-5 Environment Variables... 1-6 Executing Python from the Command Line... 1-7 IDLE...
More informationData Structures. Dictionaries - stores a series of unsorted key/value pairs that are indexed using the keys and return the value.
Data Structures Lists - stores a series of ordered mutable items Tuples - stores a series of ordered immutable items [not commonly used] Sets - stores a series of mutable or immutable(frozen) unsorted
More informationAbstract Data Types. CS 234, Fall Types, Data Types Abstraction Abstract Data Types Preconditions, Postconditions ADT Examples
Abstract Data Types CS 234, Fall 2017 Types, Data Types Abstraction Abstract Data Types Preconditions, Postconditions ADT Examples Data Types Data is stored in a computer as a sequence of binary digits:
More informationLists in Python CS 8: Introduction to Computer Science, Winter 2018 Lecture #10
Lists in Python CS 8: Introduction to Computer Science, Winter 2018 Lecture #10 Ziad Matni Dept. of Computer Science, UCSB Administrative Homework #5 is due today Homework #6 is out and DUE on MONDAY (3/5)
More informationPython Tutorial. Day 1
Python Tutorial Day 1 1 Why Python high level language interpreted and interactive real data structures (structures, objects) object oriented all the way down rich library support 2 The First Program #!/usr/bin/env
More informationMUTABLE LISTS AND DICTIONARIES 4
MUTABLE LISTS AND DICTIONARIES 4 COMPUTER SCIENCE 61A Sept. 24, 2012 1 Lists Lists are similar to tuples: the order of the data matters, their indices start at 0. The big difference is that lists are mutable
More informationIntroduction to Python. Dmytro Karpenko Research Infrastructure Services Group, Department for Research Computing, USIT, UiO
Introduction to Python Dmytro Karpenko Research Infrastructure Services Group, Department for Research Computing, USIT, UiO Research Computing Services tutorial and courses November 3-7, 2014 Why python
More informationMEIN 50010: Python Introduction
: Python Fabian Sievers Higgins Lab, Conway Institute University College Dublin Wednesday, 2017-10-04 Outline Goals Teach basic programming concepts Apply these concepts using Python Use Python Packages
More informationGetting Started Values, Expressions, and Statements CS GMU
Getting Started Values, Expressions, and Statements CS 112 @ GMU Topics where does code go? values and expressions variables and assignment 2 where does code go? we can use the interactive Python interpreter
More informationAll programs can be represented in terms of sequence, selection and iteration.
Python Lesson 3 Lists, for loops and while loops Suffolk One, Ipswich, 4:30 to 6:00 Tuesday Jan 28 Nicky Hughes All programs can be represented in terms of sequence, selection and iteration. 1 Computational
More informationPython Lists 2 CS 8: Introduction to Computer Science Lecture #9
Python Lists 2 CS 8: Introduction to Computer Science Lecture #9 Ziad Matni Dept. of Computer Science, UCSB Administrative Tutoring/Review Session Available! Friday, 5/5 at 2:00 PM in PHELPS 3526 T.A.
More informationIntroduction to Python: Data types. HORT Lecture 8 Instructor: Kranthi Varala
Introduction to Python: Data types HORT 59000 Lecture 8 Instructor: Kranthi Varala Why Python? Readability and ease-of-maintenance Python focuses on well-structured easy to read code Easier to understand
More informationSTSCI Python Introduction. Class URL
STSCI Python Introduction Class 2 Jim Hare Class URL www.pst.stsci.edu/~hare Each Class Presentation Homework suggestions Example files to download Links to sites by each class and in general I will try
More informationAt full speed with Python
At full speed with Python João Ventura v0.1 Contents 1 Introduction 2 2 Installation 3 2.1 Installing on Windows............................ 3 2.2 Installing on macos............................. 5 2.3
More informationPython. Jae-Gil Lee Based on the slides by K. Naik, M. Raju, and S. Bhatkar. December 28, Outline
Python Jae-Gil Lee Based on the slides by K. Naik, M. Raju, and S. Bhatkar December 28, 2011 1 Outline Introduction Installation and Use Distinct Features Python Basics Functional Example Comparisons with
More informationIntroduction to Python
Introduction to Python Michael Krisper Thomas Wurmitzer October 21, 2014 Michael Krisper, Thomas Wurmitzer Introduction to Python October 21, 2014 1 / 26 Schedule Tutorium I Dates & Deadlines Submission
More informationIntroduction to Python. Fang (Cherry) Liu Ph.D. Scien5fic Compu5ng Consultant PACE GATECH
Introduction to Python Ph.D. Scien5fic Compu5ng Consultant PACE GATECH Things Covered What is Python? How to access Python environment? Fundamental elements in Python Variables (assignment, comparison,
More information1. BASICS OF PYTHON. JHU Physics & Astronomy Python Workshop Lecturer: Mubdi Rahman
1. BASICS OF PYTHON JHU Physics & Astronomy Python Workshop 2017 Lecturer: Mubdi Rahman HOW IS THIS WORKSHOP GOING TO WORK? We will be going over all the basics you need to get started and get productive
More informationTopic 7: Lists, Dictionaries and Strings
Topic 7: Lists, Dictionaries and Strings The human animal differs from the lesser primates in his passion for lists of Ten Best H. Allen Smith 1 Textbook Strongly Recommended Exercises The Python Workbook:
More informationAdvanced Python. Executive Summary, Session 1
Advanced Python Executive Summary, Session 1 OBJECT: a unit of data of a particular type with characteristic functionality (i.e., methods and/or use with operators). Everything in Python is an object.
More informationCS 102 Lab 3 Fall 2012
Name: The symbol marks programming exercises. Upon completion, always capture a screenshot and include it in your lab report. Email lab report to instructor at the end of the lab. Review of built-in functions
More informationPython Programming Exercises 1
Python Programming Exercises 1 Notes: throughout these exercises >>> preceeds code that should be typed directly into the Python interpreter. To get the most out of these exercises, don t just follow them
More informationPhysics 514 Basic Python Intro
Physics 514 Basic Python Intro Emanuel Gull September 8, 2014 1 Python Introduction Download and install python. On Linux this will be done with apt-get, evince, portage, yast, or any other package manager.
More informationSequences and iteration in Python
GC3: Grid Computing Competence Center Sequences and iteration in Python GC3: Grid Computing Competence Center, University of Zurich Sep. 11 12, 2013 Sequences Python provides a few built-in sequence classes:
More informationIntroductory Linux Course. Python I. Martin Dahlö UPPMAX. Author: Nina Fischer. Dept. for Cell and Molecular Biology, Uppsala University
Introductory Linux Course Martin Dahlö UPPMAX Author: Nina Fischer Dept. for Cell and Molecular Biology, Uppsala University August, 2018 Outline Python basics get started with Python Data types Control
More informationLecture 3. Strings, Functions, & Modules
Lecture 3 Strings, Functions, & Modules Labs this Week Lab 1 is due at the beginning of your lab If it is not yet by then, you cannot get credit Only exception is for students who added late (Those students
More informationEE 355 Unit 17. Python. Mark Redekopp
1 EE 355 Unit 17 Python Mark Redekopp 2 Credits Many of the examples below are taken from the online Python tutorial at: http://docs.python.org/tutorial/introduction.html 3 Python in Context Interpreted,
More informationCS2900 Introductory Programming with Python and C++ Kevin Squire LtCol Joel Young Fall 2007
CS2900 Introductory Programming with Python and C++ Kevin Squire LtCol Joel Young Fall 2007 Course Web Site http://www.nps.navy.mil/cs/facultypages/squire/cs2900 All course related materials will be posted
More informationExercise: The basics - variables and types
Exercise: The basics - variables and types Aim: Introduce python variables and types. Issues covered: Using the python interactive shell Creating variables Using print to display a variable Simple arithmetic
More informationFlow Control: Branches and loops
Flow Control: Branches and loops In this context flow control refers to controlling the flow of the execution of your program that is, which instructions will get carried out and in what order. In the
More informationMore Examples Using Lists Tuples and Dictionaries in Python CS 8: Introduction to Computer Science, Winter 2018 Lecture #11
More Examples Using Lists Tuples and Dictionaries in Python CS 8: Introduction to Computer Science, Winter 2018 Lecture #11 Ziad Matni Dept. of Computer Science, UCSB Administrative Homework #6 is DUE
More informationIntro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming
Intro to Programming Unit 7 Intro to Programming 1 What is Programming? 1. Programming Languages 2. Markup vs. Programming 1. Introduction 2. Print Statement 3. Strings 4. Types and Values 5. Math Externals
More informationSequence types. str and bytes are sequence types Sequence types have several operations defined for them. Sequence Types. Python
Python Sequence Types Sequence types str and bytes are sequence types Sequence types have several operations defined for them Indexing Python Sequence Types Each element in a sequence can be extracted
More informationJava+- Language Reference Manual
Fall 2016 COMS4115 Programming Languages & Translators Java+- Language Reference Manual Authors Ashley Daguanno (ad3079) - Manager Anna Wen (aw2802) - Tester Tin Nilar Hlaing (th2520) - Systems Architect
More informationCS 234 Python Review Part 2
CS 234 Python Review Part 2 Recap import function: define, return boolean, conditional, branching loop: for, range, while file: open, close, readlines string: split Classes Define blueprint for a custom
More informationIntroduction to python
Introduction to python 13 Files Rossano Venturini rossano.venturini@unipi.it File System A computer s file system consists of a tree-like structured organization of directories and files directory file
More informationMore Data Structures. What is a Dictionary? Dictionaries. Python Dictionary. Key Value Pairs 10/21/2010
The Practice of Computing Using PYTHON William Punch Richard Enbody Chapter 8 Dictionaries and Sets More Data Structures We have seen the list data structure and its uses. We will now examine two, more
More informationCMPT 120 Basics of Python. Summer 2012 Instructor: Hassan Khosravi
CMPT 120 Basics of Python Summer 2012 Instructor: Hassan Khosravi Python A simple programming language to implement your ideas Design philosophy emphasizes code readability Implementation of Python was
More informationPYTHON FOR KIDS A Pl ayfu l I ntrodu ctio n to Prog r am m i ng J a s o n R. B r i g g s
PYTHON FO R K I D S A P l ay f u l I n t r o d u c t i o n to P r o g r a m m i n g Jason R. Briggs Index Symbols and Numbers + (addition operator), 17 \ (backslash) to separate lines of code, 235 in strings,
More informationShell / Python Tutorial. CS279 Autumn 2017 Rishi Bedi
Shell / Python Tutorial CS279 Autumn 2017 Rishi Bedi Shell (== console, == terminal, == command prompt) You might also hear it called bash, which is the most widely used shell program macos Windows 10+
More informationPart III Appendices 165
Part III Appendices 165 Appendix A Technical Instructions Learning Outcomes This material will help you learn how to use the software you need to do your work in this course. You won t be tested on it.
More informationCMSC 201 Computer Science I for Majors
CMSC 201 Computer Science I for Majors Lecture 02 Intro to Python Syllabus Last Class We Covered Grading scheme Academic Integrity Policy (Collaboration Policy) Getting Help Office hours Programming Mindset
More informationChapter 6: List. 6.1 Definition. What we will learn: What you need to know before: Data types Assignments
Chapter 6: List What we will learn: List definition Syntax for creating lists Selecting elements of a list Selecting subsequence of a list What you need to know before: Data types Assignments List Sub-list
More informationVariable and Data Type I
Islamic University Of Gaza Faculty of Engineering Computer Engineering Department Lab 2 Variable and Data Type I Eng. Ibraheem Lubbad September 24, 2016 Variable is reserved a location in memory to store
More informationLecture 1. Types, Expressions, & Variables
Lecture 1 Types, Expressions, & Variables About Your Instructor Director: GDIAC Game Design Initiative at Cornell Teach game design (and CS 1110 in fall) 8/29/13 Overview, Types & Expressions 2 Helping
More informationData Science Python. Anaconda. Python 3.x. Includes ALL major Python data science packages. Sci-kit learn. Pandas.
Data Science Python Anaconda Python 3.x Includes ALL major Python data science packages Sci-kit learn Pandas PlotPy Jupyter Notebooks www.anaconda.com Python - simple commands Python is an interactive
More informationSlicing. Open pizza_slicer.py
Slicing and Tuples Slicing Open pizza_slicer.py Indexing a string is a great way of getting to a single value in a string However, what if you want to use a section of a string Like the middle name of
More informationStrings. Genome 373 Genomic Informatics Elhanan Borenstein
Strings Genome 373 Genomic Informatics Elhanan Borenstein print hello, world pi = 3.14159 pi = -7.2 yet_another_var = pi + 10 print pi import math log10 = math.log(10) import sys arg1 = sys.argv[1] arg2
More informationScripting Languages. Python basics
Scripting Languages Python basics Interpreter Session: python Direct conversation with python (>>>) Python 3.5.2 (default, Nov 23 2017, 16:37:01) [GCC 5.4.0 20160609] on linux Type "help", "copyright",
More informationConstants. Variables, Expressions, and Statements. Variables. x = 12.2 y = 14 x = 100. Chapter
Variables, Expressions, and Statements Chapter 2 Unless otherwise noted, the content of this course material is licensed under a Creative Commons Attribution 3.0 License. http://creativecommons.org/licenses/by/3.0/.
More informationCS2304: Python for Java Programmers. CS2304: Sequences and Collections
CS2304: Sequences and Collections Sequences In Python A sequence type in python supports: The in membership operator. The len() function. Slicing like we saw with strings, s[1:3]. And is iterable (for
More informationChapter 1. Data types. Data types. In this chapter you will: learn about data types. learn about tuples, lists and dictionaries
Chapter 1 Data types In this chapter you will: learn about data types learn about tuples, lists and dictionaries make a magic card trick app. Data types In Python Basics you were introduced to strings
More informationPython: common syntax
Lab 09 Python! Python Intro Main Differences from C++: True and False are capitals Python floors (always down) with int division (matters with negatives): -3 / 2 = -2 No variable data types or variable
More informationPractical Workbook Computer Programming
Practical Workbook Computer Programming Name Year Batch Roll No Department: 5 th Edition Fall 2017-2018 Dept. of Computer & Information Systems Engineering NED University of Engineering & Technology, Karachi
More information