Chapter 2 2. Simple Python Data

Ace your homework & exams now with Quizwiz!

What value is printed when the following statement executes?:print(18 / 4)

4.5 (The / operator does exact division and returns a floating point result.)

Variable names #2

76trombones is illegal because it does not begin with a letter. more$ is illegal because it contains an illegal character, the dollar sign.

len

is a built-in Python function that returns the number of characters in a string ie: print(len("hello"))= 5

expression

is a combination of values, variables, operators, and calls to functions.

Value

is one of the fundamental things-like a word or a number-that a program manipulates

Variables

CAUTION: Variable names can never contain spaces

Variable names

Can be arbitrarily long. They can contain both letters and digits, but they have to begin with a letter or an underscore. Although it is legal to use uppercase letters, by convention we don't. If you do, remember that case matters. Bruce and bruce are different variables.

How can you determine the type of a variable?

Use the type function. (The type function will tell you the class the value belongs to.)

Python keywords (Keywords define the language's syntax rules and structure, and they cannot be used as variable names. )

and as assert break class continue def del elif else except exec finally for from global if import in is lambda nonlocal not or pass raise return try while with yield True False None

%

operator returns the remainder after division.

evaluation of an expression

produces a value, which is why expressions can appear on the right hand side of assignment statements. A value all by itself is a simple expression, and so is a variable. Evaluating a variable gives the value that the variable refers to.

operators

special tokens that represent computations like addition, multiplication and division

What is the data type of 'this is what kind of data'?

string ( Strings can be enclosed in single quotes.)

False (The + character is not allowed in variable names (everything else in this name is fine).)

the following is a legal variable name in Python: A_good_grade_is_A+


Related study sets

Lipid Synthesis & Lipid Storage Diseases

View Set

Life Insurance Policy Provisions, Options And Riders

View Set

Chapter 03 Equal Employment Opportunity? Aplia Assignment

View Set

World of Business Chapter 9 practice

View Set