1.isinstance 関数: 型をパラメーターとして受け取るだけでなく、型タプルもパラメーターとして受け取ることができます。
isinstance(obj,basestring)===isinstance(obj,(str,unicode))
2.getattr 関数: エラーの発生を避けるためにデフォルト値を指定できます。
writte=getattr(obj,'write',sys.stdout.write)
3.type 関数: オブジェクトの型を取得することも、そこから直接新しい型を作成することもできます:
>>> Point=type('Point',(object,),{'x':0,'y':0}) >>> p=Point() >>> p.x,p.y (0, 0) >>> p=Point(3,8) Traceback (most recent call last): File "<pyshell#55>", line 1, in <module> p=Point(3,8) TypeError: object() takes no parameters >>> pprint.pprint(dir(Point)) ['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'x', 'y'] >>> p.name='source point' >>> p.name 'source point' >>> pprint.pprint(dir(p)) ['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'name', 'x', 'y'] >>> def tostr(self): return '(%s,%s)'%(self.x,self.y) >>> Point.__str__=tostr >>> print p (0,0) >>> def init(self,x,y): self.x,self.y=x,y >>> Point.__init__=init >>> p2=Point(6,8) >>> print p2 (6,8) >>>
4.issubclass(bool,int)==True
5.numbers。すべての数値型の基本クラスです
6.type(None)==NoneType、None は定数です
7. iter(object) 形式に加えて、iter 関数はイテレータ オブジェクト (呼び出し可能、センチネル) も返します)
>>> def getrand(): import random return random.randint(1,100) >>> for i in iter(getrand,50):print i,#获取第一次得到50之前的所有1-100的随机数 32 19 82 28 30 41 100 39 71 29 45 30 94 77 62 26 25 19 82 20 55 20 43 73 >>> for i in iter(getrand,50):print i,#获取第一次得到50之前的所有1-100的随机数 22 54 14 25 60 65 16 80 61 5 48 61 2 30 90 98 70 10 55 45 23 72 87 39 70 3 84 85 >>>
8.BaseExceptionはすべての例外の基本クラスであり、Exceptionは終了しないすべての例外の単なる基本クラスです
9.locals/globals/vars/dir:
[1]locals /globals は非常に単純で、現在のスコープに相対的なローカル/グローバル オブジェクト dict です。
[2]vars()==locals()、vars(obj)==obj.__dict__
[3] にはパラメーターがありません。 , set(dir()) ==set(locals().keys()); if hasattr(obj,'__dir__')=>dir(obj)==obj.__dir__(); それ以外の場合、obj がモジュールの場合object、dir(obj) はモジュールのすべての属性を返します。obj がクラス オブジェクトの場合、dir(obj) はクラスのすべての属性を返し、obj がインスタンス オブジェクトの場合は基本クラスから継承された属性を返します。 dir(obj) は、インスタンス オブジェクトの一部の属性、それが属するクラスの属性、およびそれが属するクラスの基本クラスから継承された属性を返します。 [クラス オブジェクトへの変更はそのインスタンス オブジェクトに反映され、基本クラスへの変更は派生クラスにも反映されます。もちろん、属性マスクは除きます。 】
10.enumerate 関数: enumerate(obj,[start])、start が定義されている場合、序数はデフォルトの 0 からではなく、start から始まります。
りー
Arraysinpython、特にvianumpy、arecrucialinscientificComputing fortheirefficienty andversitility.1)彼らは、fornumericaloperations、data analysis、andmachinelearning.2)numpy'simplementation incensuresfasteroperationsthanpasteroperations.3)arayableminablecickick

Pyenv、Venv、およびAnacondaを使用して、さまざまなPythonバージョンを管理できます。 1)Pyenvを使用して、複数のPythonバージョンを管理します。Pyenvをインストールし、グローバルバージョンとローカルバージョンを設定します。 2)VENVを使用して仮想環境を作成して、プロジェクトの依存関係を分離します。 3)Anacondaを使用して、データサイエンスプロジェクトでPythonバージョンを管理します。 4)システムレベルのタスク用にシステムPythonを保持します。これらのツールと戦略を通じて、Pythonのさまざまなバージョンを効果的に管理して、プロジェクトのスムーズな実行を確保できます。

numpyarrayshaveveraladvantages-averstandardpythonarrays:1)thealmuchfasterduetocベースのインプレンテーション、2)アレモレメモリ効率、特にlargedatasets、および3)それらは、拡散化された、構造化された形成術科療法、

パフォーマンスに対する配列の均一性の影響は二重です。1)均一性により、コンパイラはメモリアクセスを最適化し、パフォーマンスを改善できます。 2)しかし、タイプの多様性を制限し、それが非効率につながる可能性があります。要するに、適切なデータ構造を選択することが重要です。

craftexecutablepythonscripts、次のようになります

numpyarraysarasarebetterfornumeroperations andmulti-dimensionaldata、whilethearraymoduleissuitable forbasic、1)numpyexcelsinperformance and forlargedatasentassandcomplexoperations.2)thearraymuremememory-effictientivearientfa

NumPyArraySareBetterforHeavyNumericalComputing、whilethearrayarayismoreSuitableformemory-constrainedprojectswithsimpledatatypes.1)numpyarraysofferarays andatiledance andpeperancedatasandatassandcomplexoperations.2)thearraymoduleisuleiseightweightandmemememe-ef

ctypesallowsinging andmanipulatingc-stylearraysinpython.1)usectypestointerfacewithclibrariesforperformance.2)createc-stylearraysfornumericalcomputations.3)passarraystocfunctions foreffientientoperations.how、how、becuutiousmorymanagemation、performanceo


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

SecLists
SecLists は、セキュリティ テスターの究極の相棒です。これは、セキュリティ評価中に頻繁に使用されるさまざまな種類のリストを 1 か所にまとめたものです。 SecLists は、セキュリティ テスターが必要とする可能性のあるすべてのリストを便利に提供することで、セキュリティ テストをより効率的かつ生産的にするのに役立ちます。リストの種類には、ユーザー名、パスワード、URL、ファジング ペイロード、機密データ パターン、Web シェルなどが含まれます。テスターはこのリポジトリを新しいテスト マシンにプルするだけで、必要なあらゆる種類のリストにアクセスできるようになります。

ドリームウィーバー CS6
ビジュアル Web 開発ツール

SAP NetWeaver Server Adapter for Eclipse
Eclipse を SAP NetWeaver アプリケーション サーバーと統合します。

SublimeText3 Linux 新バージョン
SublimeText3 Linux 最新バージョン

SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)

ホットトピック









