• Skip to main content
  • Skip to primary sidebar

学習記録

python3

改行

2017年12月31日 by 河副 太智 Leave a Comment

1
print("NumPy array: \n {}".format(aaa))

 

Filed Under: python3

変数内の要素の数を数えるlen()

2017年11月22日 by 河副 太智 Leave a Comment

len(変数)

Filed Under: python3 Tagged With: len, 要素の数

formatの代わりに%を使って小数点付きの数値を代入

2017年11月22日 by 河副 太智 Leave a Comment

1
2
3
4
5
6
7
8
9
%d -> 整数で表示
 
%f -> 小数で表示
 
%.2f -> 小数第2位まで表示
 
%s -> 文字列として表示
 
 

(例)

1
2
3
<span class="cm-variable">pai</span> = <span class="cm-number">3.141592</span>
<span class="cm-builtin">print</span>(<span class="cm-string">"円周率は%f"</span> <span class="cm-operator">%</span> <span class="cm-variable">pai</span>)  <span class="cm-comment"># 円周率は3.141592と出力されます。</span>
<span class="cm-builtin">print</span>(<span class="cm-string">"円周率は%.2f"</span> <span class="cm-operator">%</span> <span class="cm-variable">pai</span>)  <span class="cm-comment"># 円周率は3.14と出力されます。</span>

Filed Under: python3

formatの使い方

2017年11月21日 by 河副 太智 Leave a Comment

fruit = "banana"
color = "yellow"

print("{0}は{1}です".format("banana","yellow"))

Filed Under: python3

指定文字を変数内に含む個数を出力する.count()

2017年11月21日 by 河副 太智 Leave a Comment

1
2
3
4
5
<span class="cm-variable">city</span> = <span class="cm-string">"Tokyo"</span>
<span class="cm-builtin">print</span>(<span class="cm-variable">city</span>.<span class="cm-property">count</span>(<span class="cm-string">"o"</span>))  <span class="cm-comment"># 2と出力されます。
 
リストの場合
(["山形","山梨","山口","山形","山梨","山口"],"山")</span>

というのはできない、リストでは部分一致ではなく完全一致

Filed Under: python3 Tagged With: count, 位置, 変数内

sortedと.sort関数とメソッドは非破壊的と破壊的

2017年11月21日 by 河副 太智 Leave a Comment

1
2
3
4
<span class="cm-variable">alphabet</span> = [<span class="cm-string">"a"</span>,<span class="cm-string">"d"</span>,<span class="cm-string">"e"</span>,<span class="cm-string">"c"</span>,<span class="cm-string">"b"</span>]
<span class="cm-builtin">sorted</span>(<span class="cm-variable">alphabet</span>)
<span class="cm-builtin">print</span>(<span class="cm-variable">alphabet</span>)
 

adecbの順番で出力

1
2
3
4
5
<span class="cm-variable">alphabet</span> = [<span class="cm-string">"a"</span>,<span class="cm-string">"d"</span>,<span class="cm-string">"e"</span>,<span class="cm-string">"c"</span>,<span class="cm-string">"b"</span>]
<span class="cm-variable">alphabet</span>.<span class="cm-property">sort</span>()
<span class="cm-builtin">print</span>(<span class="cm-variable">alphabet</span></code><code class="cm-s-ipython language-python">)</code><code class="cm-s-ipython language-python">
 
abcdeの順番で出力

Filed Under: python3 Tagged With: メソッド, 破壊的, 関数, 非破壊的

  • « Go to Previous Page
  • Page 1
  • Interim pages omitted …
  • Page 4
  • Page 5
  • Page 6
  • Page 7
  • Page 8
  • Interim pages omitted …
  • Page 12
  • Go to Next Page »

Primary Sidebar

カテゴリー

  • AWS
  • Bootstrap
  • Dash
  • Django
  • flask
  • GIT(sourcetree)
  • Plotly/Dash
  • VPS
  • その他tool
  • ブログ
  • プログラミング
    • Bokeh
    • css
    • HoloViews
    • Jupyter
    • Numpy
    • Pandas
    • PosgreSQL
    • Python 基本
    • python3
      • webアプリ
    • python3解説
    • scikit-learn
    • scipy
    • vps
    • Wordpress
    • グラフ
    • コマンド
    • スクレイピング
    • チートシート
    • データクレンジング
    • ブロックチェーン
    • 作成実績
    • 時系列分析
    • 機械学習
      • 分析手法
      • 教師有り
    • 異常値検知
    • 自然言語処理
  • 一太郎
  • 数学
    • sympy
      • 対数関数(log)
      • 累乗根(n乗根)
    • 暗号学

Copyright © 2025 · Genesis Sample on Genesis Framework · WordPress · Log in