|
value
|
One or more values to be printed. These can be of any data type, like str, list, etc
|
|
sep
|
Separator between each value. A space by default
|
|
end
|
String to be printed at the end of the output. '\n' by default
|
|
file
|
Where the output will be printed. the console by default
|
print(value, ..., sep, end, file, flush)print('Hello, world!', file=f, end = "") equal to f.write('Hello, world!')
|
% under version 2.6
|
"%s ... text ... %d ...text... %.2f" % (var1, var2, var3) |
|
the % symbol is used as a string formatting operator. The tuple at the end is applied. %s for string variable; %d for an integer; %.nf for float with n demical places
|
|
.format() version 2.7 - 3.5
|
"{} ... {.6e} ... {:.2f}".format(var1, var2, var3) |
|
the {} symbol is used as a string formatting operator. format() at the end. {} for an integer, {.6e} for a number in scientific format with 6 demical places, etc
|
f"...text...{variable}...text..." |
|
f"{variable:^n}" |
center within a field of width n
|
f"{variable:symbole^n}" |
|
f"{variable:<n}" |
leftalign within a field of width n
|
f"{variable:>n}" |
rightalign within a field of width n
|
f"{variable:n}" |
equal to
f"{variable:>n}" |
f"{variable:d} |
integer =
int() |
{variable:.nf}" |
floating-number with n demical places
|
f"{variable:e}" |
scientific format
|
f"{variable:ne}" |
scientific format with n demical places
|
f"{var:.{int}f}" |
|
No comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.