【Python】python基礎文法 編碼

來源:互聯網
上載者:User

標籤:break   word   模組   多行注釋   oba   標準   字串   預設   字典   

  • 編碼

預設情況下,python以UTF-8編碼,所有的字串都是Unicode字串,可以為代碼定義不同的的編碼。

#coding:UTF-8#OR#-*- coding:UTF-8 -*-
  •  python保留字

保留字及為關鍵字,不能作為任何標識符名稱。查看目前的版本所有關鍵字:keyword模組

1 import keyword    #匯入keyword模組2 keyword.kwlist
[‘False‘, ‘None‘, ‘True‘, ‘and‘, ‘as‘, ‘assert‘, ‘break‘, ‘class‘, ‘continue‘, ‘def‘, ‘del‘, ‘elif‘, ‘else‘, ‘except‘, ‘finally‘, ‘for‘, ‘from‘, ‘global‘, ‘if‘, ‘import‘, ‘in‘, ‘is‘, ‘la
  • 注釋

單行注釋:代碼中以#開頭的行即為注釋,程式在執行時不會執行該行

多行注釋:"""多行注釋"""   or   ‘‘‘多行注釋‘‘

#這是一個注釋‘‘‘這是第二個注釋‘‘‘"""這是第3個注釋"""
  • 資料類型

python中有資料類型:布爾型、整型、長整型、浮點型、字串、列表、元組、字典、日期

  1. 布爾型(bool): True / False,任何數值的0,Null 字元串,空列表[],空元組(),空字典{}都是False,函數或方法傳回值為空白的同為False,其他資料都為True。
In [4]: bool(True)Out[4]: TrueIn [5]: bool(False)Out[5]: FalseIn [6]: bool(0)Out[6]: FalseIn [8]: bool([])       #空列表 Out[8]: FalseIn [9]: bool(())       #空元組Out[9]: FalseIn [10]: bool({})   #空字典Out[10]: FalseIn [12]: bool(1)Out[12]: True.................
  1. 整數(int):範圍-2**31 到2**31-1,超出這個範圍的為長整型
  2. 字串(str):被引號括起來的都是字串
#type():查看資料類型In [13]: type("hello world")Out[13]: strIn [14]: type("123")Out[14]: str
  • print()輸出

標準輸出,print()預設輸出是換行的,如果要實現不換行,需在末尾加上 end=""

>>>print("hello world!",end="","hello python!")       #不換行輸出>>>hello world! hello python!

【Python】python基礎文法 編碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.