04.08.2014 Views

o_18ufhmfmq19t513t3lgmn5l1qa8a.pdf

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

30 CHAPTER 1 ■ INSTANT HACKING: THE BASICS<br />

Strings. Strings are really simple—they are just pieces of text. And yet there is a lot to know<br />

about them. In this chapter, you’ve seen many ways to write them, and in Chapter 3 you<br />

learn many ways of using them.<br />

New Functions in This Chapter<br />

Function<br />

Description<br />

abs(number)<br />

Returns the absolute value of a number<br />

cmath.sqrt(number)<br />

Square root, also for negative numbers<br />

float(object)<br />

Converts a string or number to a floating-point number<br />

help()<br />

Offers interactive help<br />

input(prompt)<br />

Gets input from the user<br />

int(object)<br />

Converts a string or number to an integer<br />

long(object)<br />

Converts a string or number to a long integer<br />

math.ceil(number)<br />

Returns the ceiling of a number as a float<br />

math.floor(number)<br />

Returns the floor of a number as a float<br />

math.sqrt(number)<br />

Square root, not for negative numbers<br />

pow(x, y[, z]) x to the power of y (modulo z)<br />

raw_input(prompt)<br />

Gets input from the user, as a string<br />

repr(object)<br />

Returns a string-representation of a value<br />

round(number[, ndigits])<br />

Rounds a number to a given precision<br />

str(object)<br />

Converts a value to a string<br />

What Now?<br />

Now that you know the basics of expressions, let’s move on to something a bit more advanced:<br />

data structures. Instead of dealing with simple values (such as numbers), you’ll see how to<br />

bunch them together in more complex structures, such as lists and dictionaries. In addition,<br />

you’ll take another close look at strings. In Chapter 5, you learn more about statements, and<br />

after that you’ll be ready to write some really nifty programs.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!