12.07.2015 Views

Think Python - Denison University

Think Python - Denison University

Think Python - Denison University

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

Chapter 2Variables,expressions andstatements2.1 Valuesand typesA value is one of the basic things a program works with, like a letter or a number. The values wehave seen sofarare1,2,and'Hello, World!'.Thesevaluesbelongtodifferenttypes: 2isaninteger,and'Hello, World!'isastring,so-calledbecause it contains a “string” of letters. You (and the interpreter) can identify strings because theyareenclosed inquotation marks.The print statement alsoworks forintegers.>>> print 44Ifyou arenot surewhat type a value has, the interpreter can tell you.>>> type('Hello, World!')>>> type(17)Notsurprisingly,stringsbelongtothetypestrandintegersbelongtothetypeint. Lessobviously,numberswithadecimalpointbelongtoatypecalledfloat,becausethesenumbersarerepresentedinaformat called floating-point.>>> type(3.2)What about values like'17' and'3.2'? They look like numbers, but they are in quotation markslikestrings.>>> type('17')>>> type('3.2')

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

Saved successfully!

Ooh no, something went wrong!