わかりやすくするために、これを 3 つの部分に分割します。
- 変数宣言
- 入力の取得と出力の宣言
- 演算子と式
1.変数宣言
c、cpp、java などの他のプログラミング言語とは異なり、変数の型を明示的に宣言する必要はありません。この機能は ダイナミック タイピング と呼ばれます。
C では、
int a = 6;
ここでは、変数は整数として宣言されています。
ただし Python では、
a = 6
および変数 a は、
として再宣言できます。
a = "hello world"
?️注:
変数名は大文字と小文字が区別されます。そのため、a と A は別の変数とみなされます。
✨ 宣言の機能とルール
- 変数名はアルファベットまたはアンダースコア (_) で始める必要があります
a = 6 #valid _a = 6 #valid -a = 6 #invalid
- 「_」変数には、対話型 Python モードでの最後の式の結果が保存されます。これは Jupiter Notebook で確認できます
a = 5 b = 6 a + b #11 print(_) #11
- Python では、複数の変数を 1 行で宣言できます
a, b, c = 5, 6, 7
- 関数内のグローバル変数を変更するには、global キーワードを使用します
global x def print(): return x #there will be no error
- c や cpp とは異なり、Python には定数を宣言する組み込みの方法がありません。慣例により、すべて大文字の変数名は定数として扱われます。
PI=3.14
2.入力の取得と出力の宣言
print()
print() 関数は、コンソールに出力を表示するために使用される組み込み Python 関数です。
a=10000 print("hello world") #hello world print("hello", "world")#hello world print("hello world",a) #hello world 10000
print 関数には 2 つの主なパラメータがあります。
- sep : 印刷時に複数のオブジェクトをどのように分離するかを決定します。通常は「 」にプリセットされています。
- end : 出力の最後に何を出力するかを定義します。通常は「n」にプリセットされています。
例:
print("hello world") print("hi") # hello world # hi
print("hello", "world", sep="-", end = " ") print("hi") # hello-world hi
印刷の完全なドキュメントについては、ここをクリックしてください
✨ Print() の特徴
- エスケープ シーケンス (例: 改行には n、タブには t、バックスラッシュには __) を使用して、印刷出力に特殊文字を含めることができます。
print("hello\nworld") #hello #world print("hello\tworld") #hello world print("happy\trecking")#happy\trecking
- print() は、変数値とプログラムの状態を簡単に出力できるため、コード実行のデバッグやトレースによく使用されます。
x = 5 y = 10 print(f"x: {x}, y: {y}") # x: 5, y: 10
入力()
Python の input() 関数は、コンソールからユーザー入力を取得するために使用されます。
int a = 6;
?️注:
デフォルトでは、input() は文字列を返すため、入力を別の型 (int、float など) として使用する必要がある場合は、変換する必要があります。
a = 6
次回のブログでは、Python 演算子と条件文について詳しく説明します。楽しい学習???
以上がPython の基礎をマスターする日の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

forhandlinglaredataSetsinpython、usenumpyArrays forbetterperformance.1)numpyarraysarememory-effictientandfasterfornumericaloperations.2)nusinnnnedarytypeconversions.3)レバレッジベクトル化は、測定済みのマネージメーシェイメージーウェイズデイタイです

inpython、listsusedynamicmemoryallocation with allocation、whilenumpyArraysalocatefixedmemory.1)listsallocatemorememorythanneededededinitivative.2)numpyArrayasallocateexactmemoryforements、rededicablebutlessflexibilityを提供します。

inpython、youcanspecthedatatypeyfelemeremodelernspant.1)usenpynernrump.1)usenpynerp.dloatp.ploatm64、フォーマーpreciscontrolatatypes。

numpyisessentialfornumericalcomputinginpythonduetoitsspeed、memory efficiency、andcomprehensivematicalfunctions.1)それは、performsoperations.2)numpyArraysaremoremory-efficientthanpythonlists.3)Itofderangeofmathematicaloperty

contiguousMemoryAllocationisucial forArraysは、ForeffienceAndfastelementAccess.1)iteenablesConstantTimeAccess、O(1)、DuetodirectAddresscalculation.2)itemprovesefficiencyByAllowingMultiblementFechesperCacheLine.3)itimplifieMememm

slicingapythonlistisdoneusingtheyntaxlist [start:stop:step] .hore'showitworks:1)startisthe indexofthefirstelementtoinclude.2)spotisthe indexofthefirmenttoeexclude.3)staptistheincrementbetbetinelements

numpyallows forvariousoperationsonarrays:1)basicarithmeticlikeaddition、減算、乗算、および分割; 2)AdvancedperationssuchasmatrixMultiplication;

Arraysinpython、特にnumpyandpandas、aresentialfordataanalysis、offeringspeedandeficiency.1)numpyarraysenable numpyarraysenable handling forlaredatasents andcomplexoperationslikemoverages.2)Pandasextendsnumpy'scapabivitieswithdataframesfortruc


ホットAIツール

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

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

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

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

人気の記事

ホットツール

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

MinGW - Minimalist GNU for Windows
このプロジェクトは osdn.net/projects/mingw に移行中です。引き続きそこでフォローしていただけます。 MinGW: GNU Compiler Collection (GCC) のネイティブ Windows ポートであり、ネイティブ Windows アプリケーションを構築するための自由に配布可能なインポート ライブラリとヘッダー ファイルであり、C99 機能をサポートする MSVC ランタイムの拡張機能が含まれています。すべての MinGW ソフトウェアは 64 ビット Windows プラットフォームで実行できます。

SublimeText3 中国語版
中国語版、とても使いやすい

メモ帳++7.3.1
使いやすく無料のコードエディター

Dreamweaver Mac版
ビジュアル Web 開発ツール
