LoginSignup
0
1

More than 3 years have passed since last update.

動かして覚えるPythonコード一覧

Last updated at Posted at 2020-04-21

本記事について

プログラミングから長く離れていたので、練習・復讐を兼ねてPythonの超初心者用コードを実際に動かしてみました。

プログラムを実際に動かした経験を備忘録を兼ねて残しています。
誰かのお役に立てれば幸いです。

変数宣言

Pythonでは変数を事前に宣言する必要はありませんが、変数宣言は可能です。
必要性は薄いですが、可読性を高める必要がある場合などに利用します。
※実行結果は type()で確認してみてください。

# integer 型
num: int = 1

# string型
text: str = '1'

# boolean型
isEnabled: bool = True

変数名に使える文字

  • 英字(小文字)
  • 英字(大文字)
  • 数字
  • アンダースコア( _ )

変数名のルール

  • 数字から始まるものは使えない

型の確認方法

pythonは、変数宣言(型指定)の必要がありません。
何の型が設定されているか確認する場合は、オブジェクトの型を取得・確認するtype()関数を使用します。


num: int = 1
print(num , type(num))
#1 <class 'int'>

text: str = '1'
print(text, type(text))
#1 <class 'str'>

isEnabled: bool = True
print(isEnabled , type(isEnabled))
#True <class 'bool'>

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1