Preview

Formatting Code Python

Satisfactory Essays
Open Document
Open Document
451 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Formatting Code Python
PythonPython formatting codes
The on-line python documentation for the complete set of formatting codes can be found at http://docs.python.org/library/stdtypes.html#string-formatting-operations and goes further than this quick document. We have tried to select the most useful codes here. Strings We consider the string “Hello, world!”. Formatting code %s %20s %-20s %3s Hello, world! 'Hello, world' ' Hello, world!' 'Hello, world! ' 'Hello, world'

Integers We consider the integers 12,345 and -12,345. Formatting code %d %20d %-20d %020d %+d %+20d %+-20d %+020d %3d 12,345 '12345' ' 12345' '12345 ' '00000000000000012345' '+12345' ' +12345' '+12345 ' '+0000000000000012345' '12345' -12,345 '-12345' ' -12345' '-12345 ' '-0000000000000012345' '-12345' ' -12345' '-12345 ' '-0000000000000012345' '-12345'

Floating point numbers We consider the floating point numbers 12·34567 and -12·34. The %f formatting code presents data in decimal notation. The %e code does it in exponential form. Formatting code %f %20f %-20f %020f %+f %+20f %+-20f %+020f %.4f %20.4f %-20.4f %020.4f %+.4f %+20.4f %+-20.4f %+020.4f Formatting code %e %20e %-20e %020e %+e %+20e %+-20e %+020e %.4e %20.4e %-20.4e %020.4e %+.4e %+20.4e %+-20.4e %+020.4e 12·34567 '12.345670' ' 12.345670' '12.345670 ' '0000000000012.345670' '+12.345670' ' +12.345670' '+12.345670 ' '+000000000012.345670' '12.3457' ' 12.3457' '12.3457 ' '000000000000012.3457' '+12.3457' ' +12.3457' '+12.3457 ' '+00000000000012.3457' 12·34567 '1.234567e+01' ' 1.234567e+01' '1.234567e+01 ' '000000001.234567e+01' '+1.234567e+01' ' +1.234567e+01' '+1.234567e+01 ' '+00000001.234567e+01' '1.2346e+01' ' 1.2346e+01' '1.2346e+01 ' '00000000001.2346e+01' '+1.2346e+01' ' +1.2346e+01' '+1.2346e+01 ' '+0000000001.2346e+01' -12·34 '-12.340000' ' -12.340000' '-12.340000 ' '-000000000012.340000' '-12.340000' ' -12.340000' '-12.340000 ' '-000000000012.340000' '-12.3400' ' -12.3400' '-12.3400 ' '-00000000000012.3400' '-12.3400' ' -12.3400' '-12.3400 '

You May Also Find These Documents Helpful

  • Satisfactory Essays

    Nt1310 Unit 3 Maths

    • 552 Words
    • 3 Pages

    When addition or subtraction is performed, answers are rounded to the least significant decimal place.…

    • 552 Words
    • 3 Pages
    Satisfactory Essays
  • Satisfactory Essays

    NT1210 Lab 1

    • 319 Words
    • 4 Pages

    The ASCII hex code for a blank space is 20. Blank spaces are necessary to represent in text so…

    • 319 Words
    • 4 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Python has a maximum line length of 79 characters. Use one leading underscore for non-public methods and instance variables. A programmer should use two leading underscores to avoid name clashes with subclasses. Lower case words with underscores should be used for naming functions. Capitalized words with underscores…

    • 333 Words
    • 2 Pages
    Satisfactory Essays
  • Better Essays

    Nt1310 Unit 1 Assignment

    • 1994 Words
    • 8 Pages

    5. Convert 32 decimal to binary floating point. Use a 6 bit mantissa and a 4 bit exponent.…

    • 1994 Words
    • 8 Pages
    Better Essays
  • Satisfactory Essays

    Lab 1.4 ASCII

    • 349 Words
    • 3 Pages

    What is the ASCII hexadecimal code for a blank space? Why is it necessary to represent a blank space as a separate character in text? 32. Spaces are part of data.…

    • 349 Words
    • 3 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Simpsons

    • 982 Words
    • 4 Pages

    1. Rearrange these numbers in order of size, starting with the smallest and ending with the largest, in both digit form and in words. • • • • 5 078 231 5 807 123 587 321 5 780 321 Number (in Digits)…

    • 982 Words
    • 4 Pages
    Satisfactory Essays
  • Better Essays

    Answer to Question 1 a. What is the trend of murder 1960-2012?-The rate of murder over the years remained fairly constant and only slight changes were reported. The rate of murder in 1960 is almost equal to that in 2012. b. How can one explain the trend of Forcible Rape? - From the 1960s up to 1990 the rate of forcible started going down. This is attributable to the increase in police vigilance, community police, and the possible increase in the jail terms for forcible rape.…

    • 1012 Words
    • 5 Pages
    Better Essays
  • Satisfactory Essays

    essay

    • 892 Words
    • 6 Pages

    ** There is no correlation between the number of spaces provided and the number of codes!!…

    • 892 Words
    • 6 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Hmc Portfolio

    • 326 Words
    • 2 Pages

    2Notice that Exhibit 6 reports only one decimal and so you should _nd the second…

    • 326 Words
    • 2 Pages
    Satisfactory Essays
  • Powerful Essays

    My Coursework

    • 1088 Words
    • 5 Pages

    There are a number of support sites that can provide advice and suggestions for format; perhaps the most useful is:…

    • 1088 Words
    • 5 Pages
    Powerful Essays
  • Satisfactory Essays

    Square Roots And Cube Roots

    • 115 Words
    • 146 Pages

    No. Square. Cube. Sq.…

    • 115 Words
    • 146 Pages
    Satisfactory Essays
  • Powerful Essays

    • Maintain standard formatting of numbers throughout your model • Maintain standard formatting of worksheets throughout your model • Maintain standard column and row headings across multiple sheets…

    • 2666 Words
    • 11 Pages
    Powerful Essays
  • Satisfactory Essays

    Ametuer Ray

    • 4349 Words
    • 18 Pages

    3) Which of the following contains thin lines at the top and bottom of the primary strokes of the font characters?…

    • 4349 Words
    • 18 Pages
    Satisfactory Essays
  • Powerful Essays

    The following list of character codes supported by Springer is arranged as a table with 6 columns (see example below):…

    • 10693 Words
    • 43 Pages
    Powerful Essays
  • Good Essays

    Numerical Precision

    • 1181 Words
    • 5 Pages

    There are two reasons why a real number might not be exactly represented as a floating-point number. The most common situation is illustrated by the decimal number 0.1. Although it has a finite decimal representation, in binary it has an infinite repeating representation. Thus when β = 2, the number 0.1 lies strictly between two floating-point numbers and is exactly represented by neither of them (Cleve Moler).…

    • 1181 Words
    • 5 Pages
    Good Essays