摘要:數(shù)值類型整形長(zhǎng)整形有長(zhǎng)整形沒有長(zhǎng)整形浮點(diǎn)型復(fù)數(shù)類型查看幫助可以使用什么方法,實(shí)現(xiàn)什么功能共軛虛部實(shí)部初學(xué)階段,避免使用開頭的內(nèi)置功能字符串?dāng)?shù)據(jù)類型學(xué)生管理系統(tǒng)學(xué)生管理系統(tǒng)數(shù)據(jù)類型的轉(zhuǎn)換在中,所有的數(shù)據(jù)類型都可以作為內(nèi)置函數(shù),用來(lái)轉(zhuǎn)換數(shù)
數(shù)值類型 1.整形
Python 2.7.5 (default, Feb 11 2014, 07:46:25) >>> aint=3 >>> type(aint)2.長(zhǎng)整形Python 3.6.4 (default, Aug 6 2018, 22:54:20) >>> aint=3 >>> type(aint)
python2#有長(zhǎng)整形 >>> along=1728219876932764873264934692 >>> type(along)3.浮點(diǎn)型python3#沒有長(zhǎng)整形 >>> along=1728219876932764873264934692 >>> type(along)
1.344,12000000=12e6=1.2e7=0.12e7,0.012=1.2e-2
python2 >>> afloat=12e3 >>> afloat 12000.0 >>> type(afloat)4.復(fù)數(shù)類型python3 >>> afloat=12e3 >>> type(afloat)
查看幫助:可以使用什么方法,實(shí)現(xiàn)什么功能?acomplex=3j+8
type(acomplex)
help(acomplex)dir(acomplex)
["__abs__", "__add__", "__class__", "__coerce__", "__delattr__", "__div__", "__divmod__", "__doc__", "__eq__", "__float__", "__floordiv__", "__format__", "__ge__", "__getattribute__", "__getnewargs__", "__gt__", "__hash__", "__init__", "__int__", "__le__", "__long__", "__lt__", "__mod__", "__mul__", "__ne__", "__neg__", "__new__", "__nonzero__", "__pos__", "__pow__", "__radd__", "__rdiv__", "__rdivmod__", "__reduce__", "__reduce_ex__", "__repr__", "__rfloordiv__", "__rmod__", "__rmul__", "__rpow__", "__rsub__", "__rtruediv__", "__setattr__", "__sizeof__", "__str__", "__sub__", "__subclasshook__", "__truediv__", "conjugate", "imag", "real"]
>>> acomplex.conjugate() #共軛 (8-3j) >>> acomplex.imag #虛部 3.0 >>> acomplex.real #實(shí)部 8.0
初學(xué)階段,避免使用"__"開頭的內(nèi)置功能
>>> astring="hello" >>> type(astring)數(shù)據(jù)類型的轉(zhuǎn)換>>> dir(astring) ["__add__", "__class__", "__contains__", "__delattr__", "__doc__", "__eq__", "__format__", "__ge__", "__getattribute__", "__getitem__", "__getnewargs__", "__getslice__", "__gt__", "__hash__", "__init__", "__le__", "__len__", "__lt__", "__mod__", "__mul__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__rmod__", "__rmul__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "_formatter_field_name_split", "_formatter_parser", "capitalize", "center", "count", "decode", "encode", "endswith", "expandtabs", "find", "format", "index", "isalnum", "isalpha", "isdigit", "islower", "isspace", "istitle", "isupper", "join", "ljust", "lower", "lstrip", "partition", "replace", "rfind", "rindex", "rjust", "rpartition", "rsplit", "rstrip", "split", "splitlines", "startswith", "strip", "swapcase", "title", "translate", "upper", "zfill"] >>> help(astring.center) >>> astring.center(40,"*") "*****************hello******************" >>> print("學(xué)生管理系統(tǒng)".center(40,"*")) ***********學(xué)生管理系統(tǒng)***********
-在python中,所有的數(shù)據(jù)類型都可以作為內(nèi)置函數(shù),用來(lái)轉(zhuǎn)換數(shù)據(jù)類型:
>>> int(3.10) 3 >>> str(3) "3" >>> type(str(3))如何刪除內(nèi)存中的變量>>> float(3) 3.0 >>> complex(2) (2+0j)
>>> afloat=2e12 >>> del afloat >>> afloat Traceback (most recent call last): File "布爾數(shù)據(jù)類型", line 1, in NameError: name "afloat" is not defined
bool:只有兩個(gè)值(True,Flase)
>>>a = 1 >>> bool(a) True >>> bool(0) False >>> name = "we" >>> bool(a) True運(yùn)算符 1.算術(shù)運(yùn)算符
+,-,,*,/,%,//
2.賦值運(yùn)算符=,+=,-=,/=,%=,*=
3.關(guān)系運(yùn)算符,>=,<,<=,!=,==4.邏輯運(yùn)算符
邏輯與and
邏輯或or
邏輯非not
python2
>>> 5/2 2 >>> 100/300 0 >>> 5/2.0 2.5 >>> 100/300.0 0.3333333333333333 >>> from __future__ import division >>> 5/3 1.6666666666666667
python3
vim empty.py
#判斷輸入為空時(shí),輸出"Error" value=input("請(qǐng)輸入:") if not value: print("Erros")
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://specialneedsforspecialkids.com/yun/42146.html
摘要:數(shù)據(jù)類型有數(shù)字,字符串,值,列表,元組,集合,字典可變與不可變可變與不可變的區(qū)別對(duì)這個(gè)數(shù)據(jù)類型進(jìn)行增刪改差時(shí),數(shù)據(jù)存儲(chǔ)地址不變,不會(huì)開辟新的空間可變不開辟新空間不可變會(huì)改變內(nèi)存地址不可變數(shù)據(jù)類型數(shù)字,字符串,值,元組可變數(shù)據(jù)類型列表,集合, 數(shù)據(jù)類型 有:數(shù)字,字符串,bool值,列表,元組,集合,字典 可變與不可變 可變與不可變的區(qū)別:對(duì)這個(gè)數(shù)據(jù)類型進(jìn)行增刪改差時(shí),數(shù)據(jù)存儲(chǔ)地址不變,...
摘要:相等和變量在內(nèi)存中的存儲(chǔ)位置,數(shù)據(jù)類型判斷數(shù)據(jù)類型和值判斷數(shù)據(jù)類型和值直接賦值,兩者滿足列表拷貝,另外開辟內(nèi)存空間深拷貝與淺拷貝所有的數(shù)值類型布爾數(shù)字字符串都是不可變數(shù)據(jù)類型列表是可變數(shù)據(jù)類型列表里嵌套列表時(shí)淺拷貝是拷貝內(nèi)置列表的存儲(chǔ)位置深 相等 is 和== 變量id:在內(nèi)存中的存儲(chǔ)位置,id(a)value: ==type:數(shù)據(jù)類型==: 判斷數(shù)據(jù)類型和值is:判斷id,數(shù)據(jù)類型和...
摘要:函數(shù)的定義范例總結(jié)無(wú)參函數(shù)名快注釋函數(shù)體定義函數(shù),并不會(huì)執(zhí)行函數(shù)體里面的內(nèi)容調(diào)用函數(shù)的過程函數(shù)里面嵌套函數(shù)調(diào)用外層函數(shù)時(shí),內(nèi)層函數(shù)不會(huì)執(zhí)行變量參數(shù)定義函數(shù)時(shí)的變量,稱做形參,可以任意命名真實(shí)的數(shù)據(jù)信息,調(diào)用函數(shù)時(shí)傳遞的參數(shù),稱為實(shí)參是形參是 函數(shù)的定義 范例 def print(self, *args, sep= , end=n, file=None): 總結(jié) 無(wú)參 def 函數(shù)名...
摘要:列表打了激素的數(shù)組可以存儲(chǔ)任意數(shù)據(jù)類型的集和,列表里面也是可以嵌套列表的。 python工具--pycharm 安裝pycharm 官網(wǎng)下載pycharm源碼包 解壓源碼包到指定位置, 超級(jí)用戶建議解壓到/opt目錄, 普通用戶建議解壓到當(dāng)前用戶家目錄 進(jìn)入解壓目錄/opt/pycharm-community-2017.1.4/, Install-Linux-tar.txt詳細(xì)介紹...
閱讀 1269·2021-09-23 11:51
閱讀 1385·2021-09-04 16:45
閱讀 630·2019-08-30 15:54
閱讀 2080·2019-08-30 15:52
閱讀 1599·2019-08-30 11:17
閱讀 3104·2019-08-29 13:59
閱讀 2014·2019-08-28 18:09
閱讀 386·2019-08-26 12:15