Tutorial D1
11 important questions on Tutorial D1
Convertion van string-int en int-string(2)
Integer format (%d)
substitute a number and optional sign, without fractional part – float numbers are truncated
'>%d< -> 65.2|65.5|65.7|65.99999999999999999
>65<
Exponential format (%E)
substitute a number in “scientific” notation, i.e. with an “E” and exponent, with optional sign; use “%e” to for lower case exponent letter
'>%E<'
print formats1 % (65)
>6.500000E+01<
print formats1 % (65.799999999)
>6.580000E+01<
print formats1 % (0.0005)
>5.000000E-04<
print formats1 % (650)
>6.500000E+02<
- Higher grades + faster learning
- Never study anything twice
- 100% sure, 100% understanding
String format (%s):
formats1 = '>%s<'
print formats1 % ('name')
>name<
print formats1 %(65)
>65<
formats1 = '%s'
print formats1 % ('name')
name
Character format (%c):
substitute a character; if the value is an int, applies chr first
print '%c' %-85756848.8585
Traceback (most recent call last):
File "<pyshell#26>", line 1, in <module>
print '%c' %-85756848.8585-> TypeError: integer argument expected, got float
-> OverflowError: unsigned byte integer is less than minimum #print '%c' %-85756848
-> OverflowError: unsigned byte integer is greater than maximum##print '%c' %85756848
formats1 = '%c'
print formats1 % (85)
U
formats1 = '%c'
print formats1 % ('u')
u
Print formats1 % (65, 0.0001, 0.0001, 'name', 'X')
formats1 = '>%d< >%f< >%E< >%s< >%c< >%%<'
>65< >0.000100< >1.000000E-04< >name< >X< >%<
Belangrijk doel van string formatting:
String formatting: punt
String formatting: ster
String formatting: min teken
Separate field width for the fractional part.
Format6_3f = ‘>%6.3f<’
Print format6_3f % (65)
>65.000<
Of
Format6_3E = ‘>%63E<’
Print format6_3E % (65)
>6.50000E+01<
The question on the page originate from the summary of the following study material:
- A unique study and practice tool
- Never study anything twice again
- Get the grades you hope for
- 100% sure, 100% understanding