BerkeleyXData8.1x lab02.html - Lab 2 Data Types Arrays and Tables Welcome to Lab 2 Last time we had our first look at Python and Jupyter notebooks So

BerkeleyXData8.1x lab02.html - Lab 2 Data Types Arrays and...

This preview shows page 1 - 3 out of 36 pages.

Lab 2: Data Types, Arrays, and Tables Welcome to Lab 2! Last time, we had our first look at Python and Jupyter notebooks. So far, we've only used Python to manipulate numbers. There's a lot more to life than numbers, so Python lets us represent many other types of data in programs. In this lab, you'll first see how to represent and manipulate another fundamental type of data: text. A piece of text is called a string in Python. You'll also see how to invoke methods . A method is very similar to a function. Calling a method looks different because the method is tied to a particular piece of data. Last, you'll learn more about working with datasets in Python. First, initialize the OK tests. Each time you come back to this site to work on the lab, you will need to run this cell again. In [1]: from client.api.notebook import Notebook ok = Notebook('lab02.ok') ===================================================================== Assignment: Data Types in Python OK, version v1.13.11 ===================================================================== 1. Review: The building blocks of Python code The two building blocks of Python code are expressions and statements . An expression is a piece of code that is self-contained, meaning it would make sense to write it on a line by itself, and usually has a value. Here are two expressions that both evaluate to 3 3 5 - 2 One important form of an expression is the call expression , which first names a function and then describes its arguments. The function returns some value, based on its arguments. Some important mathematical functions are
Image of page 1
Function Description abs Returns the absolute value of its argument max Returns the maximum of all its arguments min Returns the minimum of all its arguments pow Raises its first argument to the power of its second argument round Round its argument to the nearest integer Here are two call expressions that both evaluate to 3 abs(2 - 5) max(round(2.8), min(pow(2, 10), -1 * pow(2, 10))) All these expressions but the first are compound expressions , meaning that they are actually combinations of several smaller expressions. 2 + 3 combines the expressions 2 and 3 by addition. In this case, 2 and 3 are called subexpressions because they're expressions that are part of a larger expression. Any expression can be used as part of a larger expression. A statement is a piece of code that makes something happen rather than having a value . For example, an assignment statement assigns a value to a name. Every assignment statement has one = sign. The whole statement is executed by evaluating the expression on the right-hand side of the equals sign and then assigning its value to the name on the left-hand side . Here are some assignment statements: height = 1.3 the_number_five = abs(-5) absolute_height_difference = abs(height - 1.688) A key idea in programming is that large, interesting things can be built by combining many simple, uninteresting things. The key to understanding a complicated piece of code is breaking it down into its simple components.
Image of page 2
Image of page 3

You've reached the end of your free preview.

Want to read all 36 pages?

  • Fall '17
  • Logarithm, Variable-length array, Test Summary

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes
A+ icon
Ask Expert Tutors