100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
Summary - Python programming $4.99   Add to cart

Summary

Summary - Python programming

 6 views  0 purchase
  • Course
  • Institution

"Dive into the world of Python programming with our comprehensive guide designed to elevate your coding skills to new heights. Whether you're a novice eager to embark on your coding journey or an experienced developer seeking to expand your expertise, this document offers a wealth of knowledge and ...

[Show more]

Preview 4 out of 164  pages

  • March 2, 2024
  • 164
  • 2005/2006
  • Summary
avatar-seller
Introduction to Python Programming
Course Notes

Phil Spector
Department of Statistics, University of California Berkeley

March 16, 2005

,2

,Contents

1 Introduction 7
1.1 What is Python? . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.2 The very Basics of Python . . . . . . . . . . . . . . . . . . . . 8
1.3 Invoking Python . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.4 Basic Principles of Python . . . . . . . . . . . . . . . . . . . . 11
1.4.1 Basic Core Language . . . . . . . . . . . . . . . . . . . 11
1.4.2 Modules . . . . . . . . . . . . . . . . . . . . . . . . . . 12
1.4.3 Object Oriented Programming . . . . . . . . . . . . . . 12
1.4.4 Namespaces and Variable Scoping . . . . . . . . . . . . 13
1.4.5 Exception Handling . . . . . . . . . . . . . . . . . . . . 15

2 String Data 17
2.1 String Constants . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.2 Special Characters and Raw Strings . . . . . . . . . . . . . . . 18
2.3 Unicode Strings . . . . . . . . . . . . . . . . . . . . . . . . . . 19
2.4 String Operations . . . . . . . . . . . . . . . . . . . . . . . . . 19
2.4.1 Concatenation . . . . . . . . . . . . . . . . . . . . . . . 19
2.4.2 Repetition . . . . . . . . . . . . . . . . . . . . . . . . . 21
2.4.3 Indexing and Slicing . . . . . . . . . . . . . . . . . . . 21
2.4.4 Functions and Methods for Character Strings . . . . . 23

3 Numeric Data 29
3.1 Types of Numeric Data . . . . . . . . . . . . . . . . . . . . . . 29
3.1.1 Hexadecimal and Octal Constants . . . . . . . . . . . . 31
3.1.2 Numeric Operators . . . . . . . . . . . . . . . . . . . . 31
3.1.3 Functions for Numeric Data . . . . . . . . . . . . . . . 32
3.2 Conversion of Scalar Types . . . . . . . . . . . . . . . . . . . . 33

3

, 4 CONTENTS

4 Lists, Tuples and Dictionaries 37
4.1 List Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
4.2 List Indexing and Slicing . . . . . . . . . . . . . . . . . . . . . 39
4.3 List Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
4.3.1 Concatenation . . . . . . . . . . . . . . . . . . . . . . . 42
4.3.2 Repetition . . . . . . . . . . . . . . . . . . . . . . . . . 43
4.3.3 The in operator . . . . . . . . . . . . . . . . . . . . . . 43
4.4 Functions and Methods for Lists . . . . . . . . . . . . . . . . . 44
4.5 Tuple Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
4.6 Operators and Indexing for Tuples . . . . . . . . . . . . . . . 49
4.7 Functions and Methods for Tuples . . . . . . . . . . . . . . . . 49
4.8 Dictionaries . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
4.9 Functions and Methods for Dictionaries . . . . . . . . . . . . . 52

5 Input and Output 55
5.1 The print command . . . . . . . . . . . . . . . . . . . . . . . 55
5.2 Formatting Strings . . . . . . . . . . . . . . . . . . . . . . . . 55
5.3 Using Names in Format Strings . . . . . . . . . . . . . . . . . 57
5.4 File Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
5.4.1 Methods for Reading . . . . . . . . . . . . . . . . . . . 59
5.4.2 Methods for Writing . . . . . . . . . . . . . . . . . . . 60
5.4.3 “Printing” to a File . . . . . . . . . . . . . . . . . . . . 60
5.4.4 Other Methods . . . . . . . . . . . . . . . . . . . . . . 61
5.4.5 File Object Variables . . . . . . . . . . . . . . . . . . . 61
5.5 Standard Input and Output Streams . . . . . . . . . . . . . . 62
5.6 Pipes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63

6 Programming 67
6.1 Assignments . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
6.2 Indentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
6.3 Truth, Falsehood and Logical Operators . . . . . . . . . . . . 72
6.4 if statement . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
6.5 for loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
6.6 for loops and the range function . . . . . . . . . . . . . . . . 78
6.7 while loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
6.8 Control in Loops: break and continue . . . . . . . . . . . . . 82
6.9 List Comprehensions . . . . . . . . . . . . . . . . . . . . . . . 84

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller EnigmaBooks. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $4.99. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

82956 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$4.99
  • (0)
  Add to cart