#! / usr / bin / python
#整数の割り当て
年齢
=
45
#浮動小数点
給与
=
1456.8
#文字列
名前
=
"John"
print
(年齢)
print
(給与)
印刷
(名前)
< / td> tr> tbody> table>
終了: b>
45 1456.8 Jo hn
Pythonで変数を作成するためのルールはsaです私は他の高級言語と同じように。
a)変数名は文字またはアンダースコアで始める必要があります。
b)変数名は数字で始めることはできません。
c)変数名には英数字とアンダースコア文字のみを含めることができます。 (Az、0-9および_)。
d)変数名では大文字と小文字が区別されます(name、Name、およびNAME&#8212;は3つの異なる変数です)。
e)予約済みの単語(キーワード)は、変数名。
1つの値を複数の変数に割り当てる:
Pythonでは、1つの値を複数の変数に同時に割り当てることもできます。
例:< / p>
#! / usr / bin / python
a
=
b
=
c
=
10
print
(a)
print
(b)
印刷
(c)
終了: b>
10 10 10
複数の変数に異なる値を割り当てる:
#! / usr / bin / python a、b、c = 1 、 20.2 、 "GeeksforGeeks" print (a ) print (b) print (c) 終了: b> 1 20.2 Python.Engineering 異なるタイプに同じ名前を使用できますか? 同じ名前を使用すると、変数は新しい1つの値とタイプを参照し始めます。 # !! / usr / bin / python a = 10 a = "GeeksforGeeks" print (a) < / td> tr> tbody> table> 終了: b> Python.Engineering +演算子は変数をどのように処理しますか? #! / usr / bin / python a = 10 b = 20 print ( + b) a = "Geeksfor" b = "Geeks" print (a + b) 終了: b> 30 Python.Engineering さまざまなタイプに+を使用できますか? さまざまなタイプに使用しないと、間違いが発生します。 < tbody> #! / usr / bin / python a = 10 b = "オタク" print ( + b) td> tr> tbody> table> 出力: TypeError:サポートされていない+のオペランドタイプ:`int`および`str` オブジェクト(またはクラスタイプ変数)の作成:強い> クラス、オブジェクト、およびメンバーを参照してください。詳細については、a>を参照してください。 #値を持つ変数を表示するPythonプログラム #クラス宣言で割り当てられ、クラス変数であり、 #コンピュータサイエンスの学生クラス クラス CSStudent: #クラス変数 ストリーム = `cse` #initメソッドまたはコンストラクター def __ init __( c ode> self 、roll): #インスタンス変数 self 。ロール = ロール # CSStudentクラスオブジェクト a = CSStudent( 101 ) b = CSStudent( 102 ) print (a.stream) #プリント&quot; cse&quot; print (b.stream) #プリント&quot; cse&quot; print (a.roll) # prints 101 #クラス変数は、クラスを使用して使用できます #nameまた、 print (CSStudent.stream) #プリント&quot; cse&quot; td> tr> tbody> table> 終了: b> cse cse 101 cse
Python変数 Python functions: Questions
Python変数 sin: Questions
Shop
Best laptop for Fortnite $
Best laptop for Excel $
Best laptop for Solidworks $
Best laptop for Roblox $
Best computer for crypto mining $
Best laptop for Sims 4 $
Best laptop for Zoom $499
Best laptop for Minecraft $590
Latest questions
NUMPYNUMPY
psycopg2: insert multiple rows with one query
12 answers
NUMPYNUMPY
How to convert Nonetype to int or string?
12 answers
NUMPYNUMPY
How to specify multiple return types using type-hints
12 answers
NUMPYNUMPY
Javascript Error: IPython is not defined in JupyterLab
12 answers
Wiki
Python OpenCV | cv2.putText () method
numpy.arctan2 () in Python
Python | os.path.realpath () method
Python OpenCV | cv2.circle () method
Python OpenCV cv2.cvtColor () method
Python - Move item to the end of the list
time.perf_counter () function in Python
Check if one list is a subset of another in Python
Python os.path.join () method
| | |