我有这个工作的测试代码:
In [16]: print "{:>20}{:0.2f}".format("", 34)
34.00
Run Code Online (Sandbox Code Playgroud)
但是我只想用一个格式的参数来做,我该怎么写呢?
我有一个方法,并希望将结果转换为具有特定格式的字符串.这是我的代码:
private double MinimunWeight()
{
return 18.5 / Math.Sqrt(Evaluation.Height).ToString("0.0");
}
Run Code Online (Sandbox Code Playgroud)
它无法编译:
运算符'/'不能应用于'double'和'string'类型的操作数
实现这一目标的正确方法是什么?
我想像2013年4月28日星期三格式化日期.任何人都知道一个简单的代码来格式化这样的日期?
此循环插入员工ID,如1,2,4,... 30.
for(int i=01;i<31;i++){
Employee e = new Employee();
e.setEmpId(i);
aList.add(e);
}
Run Code Online (Sandbox Code Playgroud)
但是,我需要01,02,03等格式的ID.有一种简单的方法可以达到这个目的吗?
Java代码示例:
public String toString() {
return (title + '\n' + border + '\n' + getEmpID() + " "
+ getLastName() + " " + getFirstName() + " "
+ getHours() + " " + getRate() + " " + getGross() + border);}
Run Code Online (Sandbox Code Playgroud)
正如您所看到的那样,它是一个很长的toString覆盖.
将代码行分解为较小位的标准位置在哪里.之前'+'的'" "'?请帮忙!:)
此外,如果你能告诉我如何正确放置{}那将是伟大的.
我是二郎的新手.我正在尝试将列表打印到控制台.
这就是我目前能够做到并且坚持下来的事情.
我正在尝试这个问题.
>List = [{"a",20},{"b", 30}].
[{"a",20},{"b",30}]
>lists:foreach( fun(H) -> io:format("~p~n", [H]) end, List).
{"a",20}
{"b",30}
Run Code Online (Sandbox Code Playgroud)
我有兴趣格式化每个列表.我希望输出是形式的
"a" - 20
"b" - 30
Run Code Online (Sandbox Code Playgroud)
我不知道如何能够访问列表中的列表并按照我希望的格式对它们进行格式化.任何形式的帮助将不胜感激.
我正在尝试使用python中的格式创建查询,我无法弄清楚我如何能够为数据转义二进制输入.它返回如下内容:
插入
python.UDP(Packet,Destination,Source,Protocol,Version,Header_Length,TTL,Protoco l_UDP,Target,Source_Port,Destination_Port,Length)VALUES(NULL,'00:0C:29:B2:14:0℃下' '192.168.178.50', '8', '4', '20',' 128','17','192.168.178.24','52371','8888','29227','b'Data\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\X00\X00\X00\X00 '');)
如何在python中使用格式化正确地转义二进制字符串值?
def setopUDP(destination, source, protocol, version, header_length, ttl, protocolEGP, target, source_port, destination_port, length, data):
query = ("INSERT INTO `python`.`UDP` (`Packet`, `Destination`, `Source`, `Protocol`, "
"`Version`, `Header_Length`, `TTL`, `Protocol_UDP`, `Target`, `Source_Port`, "
"`Destination_Port`, `Length`) VALUES (NULL, '{}', '{}', '{}', '{}', '{}', '{}', '{}', '{}', …Run Code Online (Sandbox Code Playgroud) 每当我使用print_r或var_dump他们出来所有马虎而在一行而不是格式化,就像我看到这么多人和实际的php.net网站能够实现.我该怎么办才能让他们像这样 -
Array
(
[a] => apple
[b] => banana
[c] => Array
(
[0] => x
[1] => y
[2] => z
)
)
Run Code Online (Sandbox Code Playgroud)
而不是这个
Array([a] => apple [b] => banana [c] => Array ( [0] => x [1] => y [2] => z ))
Run Code Online (Sandbox Code Playgroud)
(相当肯定它比我手工删除空格更麻烦.)
假设我有一个字典:
my_dict = {1:[1,2,3],4:[5,6,7],8:[9,10,11]}
Run Code Online (Sandbox Code Playgroud)
我想能够打印它看起来像:
1 4 8
1 5 9
2 6 10
3 7 11
Run Code Online (Sandbox Code Playgroud)
我实际上正在处理更大的字典,如果我能看到它们的外观会很好,因为我只是说它们很难阅读 print(my_dict)
我正在写一个excel vba宏.
我有一个超过10,000行的大型工作表.其中一列具有此格式的日期:10/28/13 06:57单元格具有用于格式化的常规编号.
我想将它格式化为只有这种格式的四位数字:( mmdd上例中为1028)
这是我到目前为止在子程序中的内容:
' This subroutine formats the columns to what is necessary for output
Sub formatColumns()
' Set the LastRow variable to hold the last row number
lastRow = Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row
Dim cell As Range
For Each cell In Range("B3:B" & lastRow)
cell.NumberFormat = "mmdd;@"
Next
End Sub
Run Code Online (Sandbox Code Playgroud) formatting ×10
python ×3
c# ×2
java ×2
string ×2
arrays ×1
datetime ×1
dictionary ×1
erlang ×1
escaping ×1
excel ×1
excel-vba ×1
for-loop ×1
integer ×1
mvvm ×1
php ×1
pretty-print ×1
python-3.x ×1
vba ×1