Introduction to Python

Slides:



Advertisements
Similar presentations
CS 100: Roadmap to Computing Fall 2014 Lecture 0.
Advertisements

Program Design and Development
Identifiers and Assignment Statements. Data structures In any programming language you need to refer to data The simplest way is with the actual data.
High-Level Programming Languages: C++
CIS Computer Programming Logic
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
Lists in Python.
NMED 3850 A Advanced Online Design January 26, 2010 V. Mahadevan.
Ruby! Useful as a scripting language – script: A small program meant for one time use – Targeted towards small to medium size projects Use by: – Amazon,
Computer Science 111 Fundamentals of Programming I Overview of Programming.
CS212: DATA STRUCTURES Lecture 10:Hashing 1. Outline 2  Map Abstract Data type  Map Abstract Data type methods  What is hash  Hash tables  Bucket.
Computer Science 101 Introduction to Programming.
Property of Jack Wilson, Cerritos College1 CIS Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College.
Chapter 6 Programming Languages (1) Introduction to CS 1 st Semester, 2015 Sanghyun Park.
Built-in Data Structures in Python An Introduction.
Introducing Python CS 4320, SPRING Resources We will be following the Python tutorialPython tutorial These notes will cover the following sections.
Data Collections: Lists CSC 161: The Art of Programming Prof. Henry Kautz 11/2/2009.
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.
CS105 Computer Programming PYTHON (based on CS 11 Python track: lecture 1, CALTECH)
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
Data Collections CS 127. Lists Lists are ordered sequences of items All programming languages provide a sequence structure similar to a Python list; in.
Higher Computing Science 2016 Prelim Revision. Topics to revise Computational Constructs parameter passing (value and reference, formal and actual) sub-programs/routines,
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.
Python Programing: An Introduction to Computer Science
Introduction to python programming
Web Database Programming Using PHP
Advanced Algorithms Analysis and Design
Fundamentals of Programming I Overview of Programming
Containers and Lists CIS 40 – Introduction to Programming in Python
Web Database Programming Using PHP
Introduction Algorithms Order Analysis of Algorithm
The Forth Language CSC 507 – Roy Ford November 22, 2005.
C++, OBJECT ORIENTED PROGRAMMING
Lecture 10 Data Collections
Python is a general-purpose interpreted, interactive, object-oriented, and high-level programming language. It was created by Guido van Rossum during.
JavaScript: Functions.
Lesson Outcomes Be able to identify differentiate between types of error in programs Be able to interpret error messages and identify, locate.
Introduction to Python
Chapter 8: Introduction to High-Level Language Programming
What Is a Program? A program is like an algorithm, but describes a process that is ready or can be made ready to run on a real computer Retrieved from:
Introduction to Python
Lists in Python.
Objective of This Course
An Introduction to Java – Part I, language basics
Winter 2018 CISC101 12/1/2018 CISC101 Reminders
CS190/295 Programming in Python for Life Sciences: Lecture 6
Winter 2018 CISC101 12/2/2018 CISC101 Reminders
PHP.
CS 100: Roadmap to Computing
Coding Concepts (Basics)
Web DB Programming: PHP
Chap 1 Chap 2 Chap 3 Chap 5 Surprise Me
Topics Sequences Introduction to Lists List Slicing
System Programming by Leland L. Beck Chapter 2
Python Primer 1: Types and Operators
For loops Taken from notes by Dr. Neil Moore
Topics Sequences Lists Copying Lists Processing Lists
Introduction to Computer Science
Topics Sequences Introduction to Lists List Slicing
And now for something completely different . . .
Introduction to Programming
General Computer Science for Engineers CISC 106 Lecture 03
CS 100: Roadmap to Computing
While Loops in Python.
COMPUTING.
Introduction to Computer Science
Selamat Datang di “Programming Essentials in Python”
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

Introduction to Python Usman Roshan

Python Interpreter language: the Python interpreter executes each statement one at a time. No compilation or linking is required. Python programs are called scripts which are simple text files. To execute a script we pass it through the interpreter.

Data types Basic data types Collections Integer Float String Boolean (true or false) Collections Lists Dictionaries (hash tables) Sets And more…

Expressions Numeric operators such as +, -, *, /, ** Logical operators such as and and or String operators such as in, +, [], [:] String and numeric functions such as len, abs, max, and min.

Assignment name = value Examples: sequence = “ACCCATA” x = 5 y = x + 2

Lists Ordered collection of basic types Examples: Operations on lists Concatenate: list3 = list1 + list2 Access nth element: list1[n]

Lists Time to lookup, insert, and delete We care about the worst case runtime for now We will write runtimes as a function of the input size The worst case runtime to lookup an item is the length of the list. But the time to lookup the ith item is actually constant. If we say print(l[i]) where l is a list then this takes constant time. The worst case runtime to insert an item into the list is the length of the list The worst case runtime to delete an item from the list is the length of the list

Dictionaries Dictionaries are like arrays, except that they are indexed by user defined keys instead of non-negative integers. They are also called hash-tables Example h={‘A’:’T’, ‘C’:’G’} Operations on dictionaries Lookup: h[key]

Hash-tables Time to lookup, insert, and delete We will write runtimes as a function of the input size The expected case runtime to lookup an item is constant The expected case runtime to insert an item into the list is constant The expected case runtime to delete an item from the list is constant

Input and Output Input and output to files is done by creating a file object open(path, mode) Example: f = open(“myfile.txt”,”r”) f.readline()

Control structures Conditional statements if expression : statements1 else: statements2 Example max = 0 if(x > y): max = x max = y

Iteration for count in range(start,stop,step): for item in collection: statements for item in collection: do something with item

Basic algorithmic techniques In mainstream CS one is taught: Dynamic programming Greedy algorithms Divide-and-conquer In data science and machine learning we use coordinate and gradient descent extensively What is coordinate and gradient descent?

Runtime analysis Theoretical analysis: How long does it take for an algorithm to finish as a function of input size? Real analysis: runtime in seconds depending upon machine