python-3.x - Defining in-line comments in Python
问题描述
Python has three types of comments: full-line comments, in-line comments and multi-line comments.
# Prints: "Hello World!"
print("Hello World!")
print("Hello World!") # Prints: "Hello World!"
"""
Prints:
Hello World!
"""
print("Hello World!")
Now, if you would define your own comments, it would be easy to use rstrip()
to ignore a line with an if statement where you check if your line starts with a character of your choice (||
for this example). But, that checks if a line starts with ||
. How would track your line to the point where the comment is placed, and then ignore the rest of the line?
|| Right now, only this works.
... || This doesn't.
Edit: Came up with a way myself.
line=(line.split("||")[0])
解决方案
这是答案:
line=(line.split("||")[0])
推荐阅读
- ios - 在应用升级时从 iOS 的设置屏幕中删除设置
- machine-learning - 预测神经网络中的输入
- html - type="submit" 是 IE8 到 11 中表单中按钮的默认值吗?
- data-structures - 实现链表构造函数以将值填充到特定大小
- flutter - 设置 Timepicker 并通过 http 请求触发设置时间
- java - 解码后将base64令牌转换为jsonString
- php - 如果没有 WHERE 子句,MySQL json_encode 无法读取查询
- angular - 从 Angular 卸载 npm 包
- docker - Docker 容器卷未按预期工作
- python - 使 os.path.expandvars 像在 shell 中一样扩展