pythonベースプロパティ
8446 ワード
1.pythonの特徴
他のマシン言語との違いはpythonがインタラクティブなプログラミングをサポートし、オリジナルプラットフォームでいつでも結果を表示できることです.コンパイル言語とは異なり、pythonは実行時に内容を機械言語と解釈するが、C/C++はコンパイル後、以降実行時にコンパイルを行う必要がないため、実行効率が高くなるが、pythonは強力なライブラリを持ち、拡張性が極めて強く、優位性も明らかであり、多くのシーンの使用を満たすことができ、下位言語に比べて多くの方法をカプセル化している.使用するのはもっと便利で、学ぶのは多くの时に実现の原理に関わらずことができるため、相対的に更に容易で、しかし原理を掌握するのは掌握するのが更に深いことに利益があって、だからやはり多く各种の方法の実现の原理を理解することを提案します.一つの機械言語を勉強し始める時、プログラムは背景の特徴を勉強することにすぎず、データのタイプを勉強し、データの操作(演算子とよく使われる方法と自定の方法を含む)を勉強し、その言語の核心部分(オブジェクト向けプログラミングの3つの特徴と実在、あるいはCのエッセンスポインタ部分)に入り、全体の階層の差は多くない.本文は最も基礎的な部分だけを振り返って、高級な文法oopプログラミングとsocketなどは別に記録します
2.pythonの基本構文
基本的な文法といえば変数を言わないのはもちろんだめで、他の言語とは異なり、pythonの文法では変数名、関数名、モジュール名の小文字を提唱しているが、クラス名には大アルパカルール、すなわち頭文字の大文字が推奨されている.またpythonではboolean値がTrueとFalseで大文字と小文字を区別し、解釈器の解釈が混同されないようにキーワードを避ける万年変わらないものもあります.このほか、pythonの大きな特徴は、コードブロックのレベルがインデントと協力して完成していることです.そのため、使用するときは、この2つの部分に注意してください.少なくなったり、インデントが間違ったりしても問題があります.注記では、単一の動作#が開始され、複数の行は3つの単一/二重引用符で3つの単一/二重引用符で終了します.簡単な入出力:input(「ヒント情報」)は、文字列であることに注意し、操作時にタイプ変換print(val 1,val 2,sep=',end=')を行う必要がある場合があります.デフォルトsepとendはスペースと改行で、自分で指定できます.sepはval 1とval 2の中間間隔の内容であり、endはprintに対して完了後の操作を実行し、出力時には'''でそのまま出力することもできる(使用するスペースを残して車に戻る)
3.pythonのデータ型
総じて、pythonのデータ型は数字、文字列、リスト、元祖、集合、辞書に分けられ、抽象型やクラス、オブジェクトなどを考慮すると、それぞれのデータ型は実際に使用する際にも様々な特徴があり、互いにネストされる可能性があります.以下に、さまざまなデータ型について説明します.
他のマシン言語との違いはpythonがインタラクティブなプログラミングをサポートし、オリジナルプラットフォームでいつでも結果を表示できることです.コンパイル言語とは異なり、pythonは実行時に内容を機械言語と解釈するが、C/C++はコンパイル後、以降実行時にコンパイルを行う必要がないため、実行効率が高くなるが、pythonは強力なライブラリを持ち、拡張性が極めて強く、優位性も明らかであり、多くのシーンの使用を満たすことができ、下位言語に比べて多くの方法をカプセル化している.使用するのはもっと便利で、学ぶのは多くの时に実现の原理に関わらずことができるため、相対的に更に容易で、しかし原理を掌握するのは掌握するのが更に深いことに利益があって、だからやはり多く各种の方法の実现の原理を理解することを提案します.一つの機械言語を勉強し始める時、プログラムは背景の特徴を勉強することにすぎず、データのタイプを勉強し、データの操作(演算子とよく使われる方法と自定の方法を含む)を勉強し、その言語の核心部分(オブジェクト向けプログラミングの3つの特徴と実在、あるいはCのエッセンスポインタ部分)に入り、全体の階層の差は多くない.本文は最も基礎的な部分だけを振り返って、高級な文法oopプログラミングとsocketなどは別に記録します
2.pythonの基本構文
基本的な文法といえば変数を言わないのはもちろんだめで、他の言語とは異なり、pythonの文法では変数名、関数名、モジュール名の小文字を提唱しているが、クラス名には大アルパカルール、すなわち頭文字の大文字が推奨されている.またpythonではboolean値がTrueとFalseで大文字と小文字を区別し、解釈器の解釈が混同されないようにキーワードを避ける万年変わらないものもあります.このほか、pythonの大きな特徴は、コードブロックのレベルがインデントと協力して完成していることです.そのため、使用するときは、この2つの部分に注意してください.少なくなったり、インデントが間違ったりしても問題があります.注記では、単一の動作#が開始され、複数の行は3つの単一/二重引用符で3つの単一/二重引用符で終了します.簡単な入出力:input(「ヒント情報」)は、文字列であることに注意し、操作時にタイプ変換print(val 1,val 2,sep=',end=')を行う必要がある場合があります.デフォルトsepとendはスペースと改行で、自分で指定できます.sepはval 1とval 2の中間間隔の内容であり、endはprintに対して完了後の操作を実行し、出力時には'''でそのまま出力することもできる(使用するスペースを残して車に戻る)
3.pythonのデータ型
総じて、pythonのデータ型は数字、文字列、リスト、元祖、集合、辞書に分けられ、抽象型やクラス、オブジェクトなどを考慮すると、それぞれのデータ型は実際に使用する際にも様々な特徴があり、互いにネストされる可能性があります.以下に、さまざまなデータ型について説明します.
'''
I. :
:
1. int 2. float 3. ( complex( , )) 4. ( )
: pymysql , decimal(m,n)
:import decimal
float decimal:decimal.Decimal.from_float( )
, ,
'''
'''
II.
, 。 :
'''
string = 'hello,world!'
# :
string[index]
# ,python , index , index -length<= index
, :
'''
1. (mutable) (immutable)
:list,set,dict clear(),pop(),remove()[dict remove , pop del]
:number,string,tuple
1. ( , ) ( )
* set , , , ([]) ({}) set
2. key ( )
key , set={'a':1,'a':2} key 'a' 'a'
3. :
max_result = max(zip(dict.values(),dict.keys()))
'''
4.python
python , , , , , , :
'''
1. :
+,-,* ,% : ,
/:python , , ,
//: ,
x**y: ,x y , ,pow(x,y)
2. : ==, >=, <=, !=
, None , is is not
3. : , , , java && ||
and /or : :
if a>b :
print(a)
else:
print(b)
:
a>b and print(a) or print(b)
4. :in value in dict , key value 。
5. : +=,-=,/=,//=,*=,**=
6. : &,|,^,~,<>, 、 、 、 ,
* , , , 。
: ; , 1
'''
5.python
, , while else , , (if,if...else...,if...elif...else...,while...else), (for,while), :
#for :
for i in range(0,3,1):
print(i)
# 0-2, 1 ,range , , , 1,
range , , in
#while :
count = 3
while count > 0:
count -= 1
my_str = input(' :1. 2. ')
if my_str == '1':
continue
elif my_str == '2':
break
else:
print(" ")
else:
print(' ')
'''
if while while...else
for ,while , ,
, , 1 , 2 , ,
, 2, while , else
, 2 while , else
while...else... while else, break , else;
, , python
'''
6.
, python :
# :
def my_func(args1,args2,args3=default_value):
pass
# :
def my_func(*args):
pass
# , , , ,
# , , *args , ,
# :
# :
my_func(para1,para2)
# ,
# :
my_func(args2=para2,args1=para1)
# ,
# :
# , ,
# :
# *args
# :
# , , ,
, LEGB :local,enclosing,global,built-in; enclosing ,global java static。
, , , ''' 。 lambda , , :
my_func = lambda x,y:x+y
# :
result = my_func(1,2)
7.pymysql
pymsql , , , :
import pymysql
# , , , ( 3306 , mysql , )
def my_connect(host = 'localhost',user = 'root', password = '123456', dbname = 'woniuatm'):
db = pymysql.connect(host, user, password, dbname)
return db
# pymysql
# , sql , , commit
def database_mani(sql,dbn):
db = my_connect(dbname=dbn)
cur = db.cursor()
cur.execute(sql)
db.commit()
cur.close()
db.close()
#
def database_query(sql,dbn):
db = my_connect(dbname=dbn)
cur = db.cursor()
cur.execute(sql)
result = cur.fetchone() # fetchall , fetchall ,fetchone
cur.close() # , ,fetchone , fetchall
db.close() #
return result
8.python I/O
# , , :
# / :
file = open(path,mod="",encoding="")
file.close()
# ,mod ( ),encoding , ASCII
'''
mod ( ):
r: , r,
r+: , , , , ,
w: , , , , 。 readlines
w+: , , ;readlines , ,
w w+ : , , write, open , close,
a: , ,
a+: , w , readlines
:w , , , 。 ,
a ,
:
file.readlines() ,
file.readline() , , , readlines, , readline
file.write()
'''