Python/サンプル/数値変換・文字列変換・int,str
の編集
Top
/
Python
/
サンプル
/
数値変換・文字列変換・int,str
[
トップ
] [
編集
|
差分
|
履歴
|
添付
|
リロード
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
]
-- 雛形とするページ --
(no template pages)
#navi(../) * Pytnonで数値変換・文字列変換・int,str [#sa837479] Pythonで数値のみで構成された文字列を数値に変換するintと数値を文字列に変換するstrについて紹介します。 #contents #htmlinsert(ll_ads_top.html) * 動作確認環境 [#x06bcb3a] $ python --version Python 2.7.3 $ lsb_release -d Description: Ubuntu 12.04.4 LTS * 関連記事 [#na951d00] -[[Pythonで四則演算のサンプルコード>Python/サンプル/Pythonで四則演算のサンプルコード]] -[[Pytnonで数値変換・文字列変換・int,str>Python/サンプル/数値変換・文字列変換・int,str]] -[[Pythonで小数点以下の値の操作・四捨五入や切上げ、切捨て>Python/サンプル/小数点以下の値の操作・四捨五入や切上げ、切捨て]] -[[変数のオブジェクト型を調べる方法・type>Python/サンプル/変数のオブジェクト型を調べる方法・type]] * Pythonの対話式で確認 [#k2ae3687] 以下の通り、変数a,b,cを使ってintとstrを使って変換しています。~ typeによりクラスを表示し確認しています。 $ python Python 2.7.3 (default, Sep 26 2013, 20:03:06) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> i = 100 >>> s = "200" >>> type(i) <type 'int'> >>> type(s) <type 'str'> >>> c = int(s) >>> c 200 >>> type(c) <type 'int'> >>> c = str(i) >>> type(c) <type 'str'> >>> c '100' >>> exit() * サンプルコード [#g3238738] 以下に変換し変換後のクラスを表示するサンプルコードを記します。 i = 100 s = "200" c = str(i) print type(c) c = int(s) print type(c) 上記サンプルコードの実行結果を記します。 <type 'str'> <type 'int'> 以上、数値から文字列変換と数値のみの文字列から数値変換のサンプルコード等でした。 //#htmlinsert(ll_ads_btm.html)
タイムスタンプを変更しない
#navi(../) * Pytnonで数値変換・文字列変換・int,str [#sa837479] Pythonで数値のみで構成された文字列を数値に変換するintと数値を文字列に変換するstrについて紹介します。 #contents #htmlinsert(ll_ads_top.html) * 動作確認環境 [#x06bcb3a] $ python --version Python 2.7.3 $ lsb_release -d Description: Ubuntu 12.04.4 LTS * 関連記事 [#na951d00] -[[Pythonで四則演算のサンプルコード>Python/サンプル/Pythonで四則演算のサンプルコード]] -[[Pytnonで数値変換・文字列変換・int,str>Python/サンプル/数値変換・文字列変換・int,str]] -[[Pythonで小数点以下の値の操作・四捨五入や切上げ、切捨て>Python/サンプル/小数点以下の値の操作・四捨五入や切上げ、切捨て]] -[[変数のオブジェクト型を調べる方法・type>Python/サンプル/変数のオブジェクト型を調べる方法・type]] * Pythonの対話式で確認 [#k2ae3687] 以下の通り、変数a,b,cを使ってintとstrを使って変換しています。~ typeによりクラスを表示し確認しています。 $ python Python 2.7.3 (default, Sep 26 2013, 20:03:06) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> i = 100 >>> s = "200" >>> type(i) <type 'int'> >>> type(s) <type 'str'> >>> c = int(s) >>> c 200 >>> type(c) <type 'int'> >>> c = str(i) >>> type(c) <type 'str'> >>> c '100' >>> exit() * サンプルコード [#g3238738] 以下に変換し変換後のクラスを表示するサンプルコードを記します。 i = 100 s = "200" c = str(i) print type(c) c = int(s) print type(c) 上記サンプルコードの実行結果を記します。 <type 'str'> <type 'int'> 以上、数値から文字列変換と数値のみの文字列から数値変換のサンプルコード等でした。 //#htmlinsert(ll_ads_btm.html)
テキスト整形のルールを表示する