formatting output

6
FORMATTING VARIABLES AND OUTPUT

Upload: primeteacher32

Post on 22-Feb-2017

250 views

Category:

Career


0 download

TRANSCRIPT

Page 1: Formatting  Output

FORMATTING VARIABLES AND OUTPUT

Page 2: Formatting  Output

CONSTANTS

Page 3: Formatting  Output

DATA TYPE CONVERSION

• Can control how variables are interpreted within the program:• Two types:

• Evaluation• Code: eval(string)

• Ex. eval(“51” + “52”)• eval( str1 ** str2)• test = eval(input(“Enter a num”))

• Conversion• Code: datatype(value/variable)

• Ex. int(4.5) 4• float(4) 4.0• str(num) “4”

Page 4: Formatting  Output

THE ESCAPE SEQUENCE• Used within a string to perform a specific task

• Code: print(“\”This is an example\”\n”)

Page 5: Formatting  Output

FORMATTING OUTPUT• Controls how the information is displayed:

• size• Position• Justification• padding• number of digits• Dataytype

• The format function formats a number, string, or both and returns the information as a string.

• Code: format(variable, ‘format-specifier’)

Page 6: Formatting  Output

THE FORMAT FUNCTION

Code: print(format(item, ‘ ’)