干货太多了,天哪
1.Try and except
>>> try:
import flask
except:
print("No mudule named flask")
No mudule named flask
>>>
2 Comments , Triple quotation marks,Back-salsh
2.1
用#注释。#之后的语句不会运行。
2.2
"""
Write anything you want.
Can span multiple lines.
"""
"""
Or three single quotation marks ''' '''
"""
2.3
\ character is a way we can put difficult-to-type characters into a string.
Escape What it does.
\\ Backslash (\)
\' Single-quote (')
\" Double-quote (")
\a ASCII bell (BEL)
\b ASCII backspace (BS)
\f ASCII formfeed (FF)
\n ASCII linefeed (LF)
\N{name} Character named name in the Unicode database (Unicode only)
\r Carriage Return (CR)
\t Horizontal Tab (TAB)
\uxxxx Character with 16-bit hex value xxxx (Unicode only)
\Uxxxxxxxx Character with 32-bit hex value xxxxxxxx (Unicode only)
\v ASCII vertical tab (VT)
\ooo Character with octal value ooo
\xhh Character with hex value hh
来自 <https://learnpythonthehardway.org/book/ex10.html>
一行代码太长的时候,可以用 \ 来换行。
>>> longitude = 118.06
>>> latitude = 24.27
>>> if 118.00000000 < longitude < 118.22222222\
and 24.22222222 < latitude < 29.66666666 :
print("Somewhere.")
else:
print("Somewhere else.")
Somewhere.
>>>

本文介绍了Python中处理异常的方法,使用try-except结构来捕获并处理导入模块失败的情况。此外,还讲解了如何使用注释、多行字符串以及转义字符等语法技巧,并展示了如何通过使用反斜杠进行代码换行。
439

被折叠的 条评论
为什么被折叠?



