Casio Python - type()

Python Casio Python
 Casioグラフ関数電卓の Python を使ってみる
     - リファレンス 
目次
type()


初版:2020/07/05

[対応モデル] - fx-CG50 OS3.20 以降、fx-9750GIII / fx-9860GIII OS3.21 以降


オブジェクトを与えると、オブジェクトの型を返します。


スクリプト例:
print(type(1234))  #整数型 (int型)
print(type(12.34))  #浮動小数点型 (float型)
print(type('abcd'))  #文字列型 (str型)
print(type(['a', 'b', 1, 2]))  #リスト型 (list型)
print(type(1, 2, 3, 4))  #タプル型 (tuple型)
print(type({'one':'eins', 'two':'zwei', 'three':'drei'}))  #辞書型 (dict型)
print(type({1, 2, 3, 4}))  #集合型 (set型)

if type(1234) is int:  #整数型なら 'int' と出力
 print('int')
if type(12.34) is float:  #不動小数点型なら 'float' と出力
 print('float')
if type('abcd') is str:  #文字列型なら 'str' と出力
 print('str')
if type(['a', 'b', 1, 2]) is list:  #リスト型なら 'list' と出力
 print('list')
if type((1, 2, 3, 4)) is tuple:  #タプル型なら 'tuple' と出力
 print('tuple')
if type({'one':'eins', 'two':'zwei', 'three':'drei'}) is dict:  #辞書型なら'dict'と出力
 print('dict')
if type({1, 2, 3, 4}) is set:  #集合型なら 'set' と出力
 print('set')

動作:
実行結果は、下記になります。
<class 'int'>
<class 'float'>
<class 'str'>
<class 'list'>
<class 'tuple'>
<class 'dict'>
<class 'set'>

int
float
str
list
tuple
dict
set

Casio Python の組込データ型、int型(整数型)、float型(浮動小数点型)、str型(文字列型)、list型(リスト型)、tuple型(タプル型)、dict型(辞書型)、set型(集合型)の判定を行っています。
前半は print() を使って、データ型をそのまま表示しています。
後半は、is ステートメントを使った判定を行っています (実際によく使う例だと思います)。





応援クリックをお願いします。励みになるので...
にほんブログ村 IT技術ブログ 開発言語へ


 


keywords: fx-CG50Pythonfx-9750GIIIfx-9860GIIIプログラム関数電卓

リンク集 | ブログ内マップ

関連記事

テーマ : プログラム関数電卓
ジャンル : コンピュータ

コメントの投稿

非公開コメント

最新記事
検索フォーム
最新コメント
カテゴリ
C# (3)
Online Counter
現在の閲覧者数:
プロフィール

やす (Krtyski)

Author:やす (Krtyski)
since Oct 30, 2013


プログラム電卓は、プログラムを作って、使ってナンボ!

プログラム電卓を実際に使って気づいたこと、自作プログラム、電卓での Casio Basic, C.Basic そして Casio Python プログラミングについて書いています。

なお管理人はカシオ計算機の関係者ではありません。いつでもどこでもプログラミングができるプログラム電卓が好きな1ユーザーです。


写真: 「4駆で泥んこ遊び@オックスフォード郊外」

リンク
月別アーカイブ
Sitemap

全ての記事を表示する

ブロとも申請フォーム

この人とブロともになる

QRコード
QR