Xi Wang Yang Zhang. 1. Easy to learn 2. Clean and readable codes 3. A lot of useful packages, especially for web scraping and text mining 4. Growing popularity.

Slides:



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

Why python? Automate processes Batch programming Faster Open source Easy recognition of errors Good for data management What is python? Scripting programming.
Conditional Statements Introduction to Computing Science and Programming I.
Chapter 4 Control Structures I. Objectives ► Examine relational and logical operators ► Explore how to form and evaluate logical (Boolean) expressions.
July 13 th.  If/ Else if / Else  Variable Scope  Nested if/else's  Switch statements  Conditional Operator.
Slide 1 Summary Two basic concepts: variables and assignments Some C++ practical issues: division rule, operator precedence  Sequential structure of a.
Basic Elements of Programming A VB program is built from statements, statements from expressions, expressions from operators and operands, and operands.
Python November 18, Unit 7. So Far We can get user input We can create variables We can convert values from one type to another using functions We can.
Intro to Robots Conditionals and Recursion. Intro to Robots Modulus Two integer division operators - / and %. When dividing an integer by an integer we.
INTRODUCTION TO PYTHON PART 3 - LOOPS AND CONDITIONAL LOGIC CSC482 Introduction to Text Analytics Thomas Tiahrt, MA, PhD.
Recitation 1 Programming for Engineers in Python.
Python Programming Fundamentals
Python – Part 4 Conditionals and Recursion. Modulus Operator Yields the remainder when first operand is divided by the second. >>>remainder=7%3 >>>print.
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
Python Lab: Control Statements Conditionals, Loops, Iterations Proteomics Informatics, Spring 2014 Week 4 18 th Feb, 2014
Introduction to Python Basics of the Language. Install Python Find the most recent distribution for your computer at:
Introduction to Programming Workshop 1 PHYS1101 Discovery Skills in Physics Dr. Nigel Dipper Room 125d
Computer Science 111 Fundamentals of Programming I Overview of Programming.
Python – Making Decisions Lecture 02. Control Structures A program that only has one flow is useful but limited. We can use if statements to make these.
CPTR 124 Review for Test 1. Development Tools Editor Similar to a word processor Allows programmer to compose/save/edit source code Compiler/interpreter.
1 CSC 221: Introduction to Programming Fall 2012 Functions & Modules  standard modules: math, random  Python documentation, help  user-defined functions,
Control Structures – Selection Chapter 4 2 Chapter Topics  Control Structures  Relational Operators  Logical (Boolean) Operators  Logical Expressions.
Introduction to Computing Using Python Imperative Programming  what is a Python program?  print() statement  input() statement  type conversion statements.
C463 / B551 Artificial Intelligence Dana Vrajitoru Python.
Python uses boolean variables to evaluate conditions. The boolean values True and False are returned when an expression is compared or evaluated.
CSC 110 Using Python [Reading: chapter 1] CSC 110 B 1.
Python Mini-Course University of Oklahoma Department of Psychology Day 2 – Lesson 7 Conditionals and Loops 4/18/09 Python Mini-Course: Day 2 - Lesson 7.
Introduction to Matlab Module #4 Page 1 Introduction to Matlab Module #4 – Programming Topics 1.Programming Basics (fprintf, standard input) 2.Relational.
Python Conditionals chapter 5
Python – Part 3 Functions 1. Getting help Start the Python interpreter and type help() to start the online help utility. Or you can type help(print) to.
Boolean Expressions and Logical Operators CSE 1310 – Introduction to Computers and Programming Alexandra Stefan University of Texas at Arlington Credits:
CONDITIONALS. Boolean values Boolean value is either true or false It is name after the British mathemetician, George Boole who first formulated Boolean.
Python Mini-Course University of Oklahoma Department of Psychology Day 3 – Lesson 10 Iteration: Loops 05/02/09 Python Mini-Course: Day 3 - Lesson 10 1.
The If Statement There are no switch statements in Python. You need to use just if statements. There are no switch statements in Python. You need to use.
1. COMPUTERS AND PROGRAMS Rocky K. C. Chang September 6, 2015 (Adapted from John Zelle’s slides)
Control structures in C by Dr P.Padmanabham Professor (CSE)&Director Bharat Institute of Engineering &Technology Hyderabad Mobile
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
Introduction to Programming Python Lab 7: if Statement 19 February PythonLab7 lecture slides.ppt Ping Brennan
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
Python – Part 4 Conditionals and Recursion. Conditional execution If statement if x>0:# CONDITION print (‘x is positive’) Same structure as function definition.
PROGRAMMING USING PYTHON LANGUAGE ASSIGNMENT 1. INSTALLATION OF RASPBERRY NOOB First prepare the SD card provided in the kit by loading an Operating System.
PYTHON PROGRAMMING. WHAT IS PYTHON?  Python is a high-level language.  Interpreted  Object oriented (use of classes and objects)  Standard library.
IST 210: PHP Logic IST 210: Organization of Data IST2101.
Python Basics.
Fundamentals of Programming I Overview of Programming
Control Flow (Python) Dr. José M. Reyes Álamo.
Introduction to Python
Making Choices with if Statements
Module 3.
Python: Control Structures
Introduction to Programming
Data Analysis using Python-I
Control Structures – Selection
PH2150 Scientific Computing Skills
Imperative Programming
First Python Program Professor Hugh C. Lauer CS-1004 — Introduction to Programming for Non-Majors (Slides include materials from Python Programming: An.
Types, Truth, and Expressions (Part 2)
Types, Truth, and Expressions (Part 2)
CS 100: Roadmap to Computing
Python Tutorial for C Programmer Boontee Kruatrachue Kritawan Siriboon
Computer Science Core Concepts
Introduction to Programming with Python
Understanding Conditions
COMPUTER PROGRAMMING SKILLS
12th Computer Science – Unit 5
General Computer Science for Engineers CISC 106 Lecture 03
CS 100: Roadmap to Computing
Imperative Programming
Introduction to Python
Control 9 / 25 / 19.
Presentation transcript:

Xi Wang Yang Zhang

1. Easy to learn 2. Clean and readable codes 3. A lot of useful packages, especially for web scraping and text mining 4. Growing popularity

 Installing Python   Online Learning resources  How to Think Like a Computer Scientist  sh2e/ sh2e/  Code Academy   Edx: Introduction to Computer Science and Programming Using Python 

1. Python Shell  Windows: command prompt  Mac: terminal 2. Script 3. Integrated Development Environment (IDE)

1. Write a program in a text editor and save it as a.py file.

2. Run the script in a Python shell.

 An IDE normally consists of a source code editor, build automation, and a debugger.  Python IDEs  ated_development_environments ated_development_environments  Example: Enthought Canopy

1. Variables 2. Functions 3. Conditionals 4. Iteration  Slides and example codes can be downloaded from

 Everything in a Python program belongs to a data type: >>> type(5) >>> type(1.23)

>>> type(“Hello, World!”) >>> type(‘Hello, Iowa!’) >>> type(‘5’) >>> type(True) >>> type(False)

 Data types can be changed: >>> float(5) 5.0 >>> str(5) ‘5’ >>> int(1.9) 1 >>> int(‘5’) 5 >>> int(True) 1

 A variable is a name that refers to a value.  The assignment statement creates new variables and gives them values: >>> message = “What’s up?” >>> n = 18 >>> pi = 3.14

 Print statement shows the content of a variable: >>> print message What’s up? >>> print n 18 >>> print pi 3.14

 Variables can be changed: >>> count = 10 >>> count = count – 1 >>> print count 9 >>> count -= 1 >>> print count 8

 Python is a calculator: >>> x = 10 >>> y = 2 >>> z1 = 3 >>> z2 = 3.0

>>> x / y 5 >>> x / z1 3 >>> x /z

 A function is a named sequence of statements that performs a desired operation.  Python has many useful built-in functions. For example: >>> type(5) Int >>> abs(-10) 10 >>> max(1,2,3) 3

 In Python, the syntax for a function definition is: def NAME(PARAMETERS): STATEMENTS Be cautious with indentation!

 For example: >>> def myMean(a,b): return (a+b)/2 >>> myMean(3,5) 4

 Default parameter values >>> def discArea(r, pi=3): return pi*(r**2) >>> discArea(2) 12 >>> discArea(2, 3.14) >>> discArea(r=2, pi=3.14) 12.56

 A module is a neatly packaged set of functions. Some come with Python, others need to be installed.  For example, to know your current working directory: >>> import os >>> os.getcwd() 'C:\\Users\\Yang' >>> from os import getcwd >>> getcwd() 'C:\\Users\\Yang'

 There are only two Boolean values.  True  False  A Boolean expression returns a Boolean value. >>> 5 == 5 True >>> 5 == 6 False

x = 5 y = 6 >>> x == y False >>> x != y True >>> x > y False >>> x < y True What will happen if we type x = y?

 Logical operators connect multiple Boolean expressions. >>> 3 > 0 and 3 < 5 True >>> 3 < 2 or 3 < 1 False >>> not(5 > 6) True

 Conditional statements take a form like this: if BOOLEAN EXPRESSION: STATEMENTS >>> x = 5 >>> if x > 0: print 'x is positive.' x is positive.

 Alternative Execution >>> def isEven(x): if x % 2 == 0: return True else: return False >>> isEven(5) False >>> isEven(6) True

 Conditionals can be chained: >>> x = 5 >>> y = 6 >>> if x < y: print x, "is less than", y elif x > y: print x, "is greater than", y else: print x, "and", y, "are equal" 5 is less than 6

 Conditionals can be nested: >>> if x == y: print x, "and", y, "are equal" else: if x < y: print x, "is less than", y else: print x, "is greater than", y 5 is less than 6

 Iteration is repeated execution of a set of statements. 1. The while statement 2. The for statement

 The while statement >>> def countdown(n): while n > 0: print n n = n-1 print "Blastoff!" >>> countdown(3) Blastoff!

 The for statement >>>for x in 'Iowa': print x I o w a

 Introduction to Python  Introduction to R  Stata Programming  Introduction to ArcGIS  Multilevel Modeling in R and Stata