의 문자열은 그래서 첫 번째 줄이 너무 긴LINEBREAK 파이썬 소스 코드
return "Cargo(location=%s, cargocapacity=%s, cargo=%s, name=%s, mast_count=%s)" \
% (
self.location,
self.cargocapacity,
self.cargo,
self.name,
self.mast_count)
있습니다. 어떻게하면 선을 깰 수 있을까요? 내가
return "Cargo(location=%s, cargocapacity=%s, cargo=%s, \
name=%s, mast_count=%s)" \
% (
self.location,
self.cargocapacity,
self.cargo,
self.name,
self.mast_count)
을하고 반환 된 문자열을 인쇄 할 경우 난 withespace 많이 얻을.
이 방법이 있습니까? 어쩌면 단일 인수로 문자열을 결합 할 수 있습니까? 그러나 이것은 많은 코드 라인을 추가 할 것입니다.
템플릿 사용을 고려하십시오. 'template = "Cargo (location = {location}, cargocapacity = {cargocapacity}, cargo = {cargo}, name = {name}, mast_count = {mast_count})"; return template.format (self)' – wim
속성의'str' 형식이 아닌'repr'이 필요할 것입니다. – jonrsharpe