Fast Lane to Python - UC Davis

Fast Lane to Python

A quick, sensible route to the joys of Python coding

Norm Matloff University of California, Davis

This work is licensed under a Creative Commons Attribution-No Derivative Works 3.0 United States License. Copyright is retained by N. Matloff in all non-U.S. jurisdictions, but permission to use these materials in teaching is still granted, provided the authorship and licensing information here is displayed. The author has striven to minimize the number of errors, but no guarantee is made as to accuracy of the contents of this book.

2

Author's Biographical Sketch

Dr. Norm Matloff is a professor of computer science at the University of California at Davis, and was formerly a professor of statistics at that university. Dr. Matloff was born in Los Angeles, and grew up in East Los Angeles and the San Gabriel Valley. He has a PhD in pure mathematics from UCLA, His current research interests are in machine learning, parallel processing, statistical computing, and statistical methodology for handling missing data. Prof. Matloff is a former appointed member of IFIP Working Group 11.3, an international committee concerned with database software security, established under the United Nations. He was a founding member of the UC Davis Department of Statistics, and participated in the formation of the UCD Computer Science Department as well. He is a recipient of the campuswide Distinguished Teaching Award and Distinguished Public Service Award at UC Davis. Dr. Matloff has served as Editor-in-Chief of the R Journal, and served on the editorial board of the Journal of Statistical Software. Dr. Matloff is the author of several published textbooks. His book Statistical Regression and Classification: from Linear Models to Machine Learning, won the Ziegel Award in 2017.

3

4

Contents

1 Introduction

1

1.1 A 5-Minute Introductory Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

1.1.1 Example Program Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

1.1.2 Python Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

1.1.3 Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

1.1.4 Python Block Definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

1.1.5 Python Also Offers an Interactive Mode . . . . . . . . . . . . . . . . . . . . . . . . 5

1.1.6 Python As a Calculator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

1.2 A 10-Minute Introductory Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

1.2.1 Example Program Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

1.2.2 Command-Line Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

1.2.3 Introduction to File Manipulation . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

1.2.4 Lack of Declaration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

1.2.5 Locals Vs. Globals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

1.2.6 A Couple of Built-In Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

1.3 Types of Variables/Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

1.4 String Versus Numerical Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

1.5 Sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

1.5.1 Lists (Quasi-Arrays) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

i

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download