Python3学习笔记3-try and except, comment, \(back-slash)

来源:互联网 发布:linux查看进程端口 编辑:程序博客网 时间:2024/06/11 16:37

干货太多了,天哪

1.Try and except

>>> try:    import flaskexcept:    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.>>> 
原创粉丝点击