Python中文
首页
教程
问答
标签
搜索
登录
注册
创建长多行字符串的Pythonic方法
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我有一个很长的问题。我想用Python把它分成几行。用JavaScript实现这一点的一种方法是使用几个句子,并用一个<code>+</code>操作符将它们连接起来(我知道,这可能不是最有效的方法,但我并不真正关心这个阶段的性能,只关心代码的可读性)。示例:</p> <pre><code>var long_string = 'some text not important. just garbage to' + 'illustrate my example'; </code></pre> <p>我尝试在Python中做类似的事情,但是没有成功,所以我使用<code>\</code>来分割长字符串。但是,我不确定这是否是唯一的/最好的/Python式的方法。看起来很尴尬。 实际代码:</p> <pre><code>query = 'SELECT action.descr as "action", '\ 'role.id as role_id,'\ 'role.descr as role'\ 'FROM '\ 'public.role_action_def,'\ 'public.role,'\ 'public.record_def, '\ 'public.action'\ 'WHERE role.id = role_action_def.role_id AND'\ 'record_def.id = role_action_def.def_id AND'\ 'action.id = role_action_def.action_id AND'\ 'role_action_def.account_id = ' + account_id + ' AND'\ 'record_def.account_id=' + account_id + ' AND'\ 'def_id=' + def_id </code></pre>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>用<code>\</code>来断线对我很有用。下面是一个例子:</p> <pre><code>longStr = "This is a very long string " \ "that I wrote to help somebody " \ "who had a question about " \ "writing long strings in Python" </code></pre>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
将Pandas数据帧转换为PyTorch张量?
8 回答
将Pandas数据帧转换为scipy稀疏矩阵
7 回答
将Pandas数据帧转换为Spark Datafram时出现问题
10 回答
将pandas数据帧转换为spark DataFram时出错
1 回答
将Pandas数据帧转换为spark datafram时收到错误
7 回答
将Pandas数据帧转换为Spark数据帧
7 回答
将Pandas数据帧转换为Tensorflow数据
5 回答
将Pandas数据帧转换为tkinter obj
7 回答
将pandas数据帧转换为XML
6 回答
将Pandas数据帧转换为值sql语句
3 回答
将pandas数据帧转换为元组
10 回答
将pandas数据帧转换为元组列表
2 回答
将pandas数据帧转换为元组列表并删除所有pandas数据类型
8 回答
将pandas数据帧转换为具有头和数据类型的numpy数组
4 回答
将pandas数据帧转换为内存中的拼花地板,并将其加载到Python中的Hadoop中
1 回答
将pandas数据帧转换为内存中类似文件的对象?
10 回答
将Pandas数据帧转换为内存功能(&F)
1 回答
将pandas数据帧转换为列表列表
10 回答
将pandas数据帧转换为列表列表以输入到RNN
6 回答
将Pandas数据帧转换为单行DataFram
3 回答