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

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

干货太多了,天哪

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.
>>> 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值