=>
Var = 'This is a String'
Var = "This is a String"
Var = '''This is a String'''
Var = """This is a String"""
與 Bash shell 不同,這四種型態的引號對Python來講在功能上是一樣的,Python提供四種型態的引號主要是要讓使用者在建立字串時可以有更多的彈性。
例如當使用單引號括住字串,而字串中又出現縮寫,Python會認為引號不成對,因此就會發生語法錯誤。
=>
Var = 'This isn't a string'
>>> Var = 'This isn't a string' File "<stdin>", line 1 Var = 'This isn't a string' ^ SyntaxError: invalid syntax |
這時就可以改用雙引號或三引號括住字串來解決這個問題。
=>
Var = "This isn't a string"
Var = '''This isn't a string'''
<<<<<回 Learning Python 目錄>>>>>
沒有留言:
張貼留言