• Skip to main content
  • Skip to primary sidebar

学習記録

プログラミング

リストの要素を削除

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

1
2
3
4
5
6
<span class="cm-variable">alphabet</span> = [<span class="cm-string">"a"</span>, <span class="cm-string">"b"</span>, <span class="cm-string">"c"</span>, <span class="cm-string">"d"</span>, <span class="cm-string">"e"</span>]
<span class="cm-keyword">del</span>(<span class="cm-variable">alphabet</span>[<span class="cm-number">3</span>:])
<span class="cm-keyword">del</span>(<span class="cm-variable">alphabet</span>[<span class="cm-number">0</span></code><code class="cm-s-ipython language-python">])</code><code class="cm-s-ipython language-python">
<span class="cm-builtin">print</span>(<span class="cm-variable">alphabet</span>)  <span class="cm-comment"># ["b", "c"]が出力される
 
</span>

  • del(リスト[インデックス番号])

 

例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
In [9]: sample_list = ['a','b','c','d','e']
 
In [10]: sample_list[0]
Out[10]: 'a'
 
In [11]: sample_list[0:]
Out[11]: ['a', 'b', 'c', 'd', 'e']
 
In [12]: sample_list[0:-1]
Out[12]: ['a', 'b', 'c', 'd']
 
In [13]: sample_list[0:4]
Out[13]: ['a', 'b', 'c', 'd']
 
In [19]: sample_list[-3:]
Out[19]: ['c', 'd', 'e']
 
In [22]: sample_list[-3:-1]
Out[22]: ['c', 'd']
 
# リストを反転させるとき
In [14]: sample_list[::-1]
Out[14]: ['e', 'd', 'c', 'b', 'a']

1
 

Filed Under: python3

リスト

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

1
2
3
4
5
6
7
8
9
<span class="cm-variable">alphabet</span> = [<span class="cm-string">"a"</span>, <span class="cm-string">"b"</span>, <span class="cm-string">"c"</span>, <span class="cm-string">"d"</span>, <span class="cm-string">"e"</span>]
<span class="cm-variable">alphabet</span>[<span class="cm-number">0</span>] = <span class="cm-string">"A"</span>
<span class="cm-variable">alphabet</span>[<span class="cm-number">1</span>:<span class="cm-number">3</span>] = [<span class="cm-string">"B"</span>, <span class="cm-string">"C"</span>]
</code><code class="cm-s-ipython language-python"><span class="cm-builtin">print</span></code><code class="cm-s-ipython language-python">(<span class="cm-variable">alphabet</span>)  </code><code class="cm-s-ipython language-python"><span class="cm-comment"># ["A", "B", "C", "d", "e"]が出力される</span></code><code class="cm-s-ipython language-python">
 
<span class="cm-variable">alphabet</span> = <span class="cm-variable">alphabet</span> <span class="cm-operator">+</span> [<span class="cm-string">"f"</span>]
<span class="cm-variable">alphabet</span> += [<span class="cm-string">"g"</span>,<span class="cm-string">"h"</span>]
<span class="cm-variable">alphabet</span>.<span class="cm-property">append</span>(<span class="cm-string">"i"</span>)
<span class="cm-builtin">print</span>(<span class="cm-variable">alphabet</span>) <span class="cm-comment"># ["A", "B", "C", "d", "e", "f", "g", "h", "i"]が出力される</span>

Filed Under: python3

pass とcontinueの違い ifを抜ける

2017年10月30日 by 河副 太智 Leave a Comment

passだとifを抜ける
continueだとifの中のelifも実行される。

 

■continueの場合以下のelifは実行される

1
2
3
4
if len(ans) != 6:
continue(elifは実行される)
elif ans.isdecimal() == False:
print "a"

 

■passの場合以下のelifは実行されない

1
2
3
4
if len(ans) != 6:
pass (elifは実行されない)
elif ans != c[0]:
print "a"

 

Filed Under: python3

変数が空かどうかを確認

2017年10月25日 by 河副 太智 Leave a Comment

if a is None:

Filed Under: python3

HTMLヘッダー

2017年10月25日 by 河副 太智 Leave a Comment

print('Content-type: text/html; charset=UTF-8\r\n')
print("""
<html>
<head>
<title>2017年度HSコードを旧HSコードに変換</title>
<link rel="stylesheet" type="text/css" href="form.css">
</head>
<body>

Filed Under: python3

文字列の数値判定

2017年10月25日 by 河副 太智 Leave a Comment

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# 半角数字
print("1".isdigit()) # True
print("1".isdecimal()) # True
print("1".isnumeric()) # True
# 半角数値(符号付き)
print("0.01".isdigit()) # False
print("0.01".isdecimal()) # False
print("0.01".isnumeric()) # False
 
# 半角数値(小数)
print("0.01".isdigit()) # False
print("0.01".isdecimal()) # False
print("0.01".isnumeric()) # False
# U+0660を含む場合
print("0٠01".isdigit()) # True
print("0٠01".isdecimal()) # True
print("0٠01".isnumeric()) # True
# 全角数字
print("1".isdigit()) # True
print("1".isdecimal()) # True
print("1".isnumeric()) # True
# 全角漢数字
print("百".isdigit()) # False
print("百".isdecimal()) #  False
print("百".isnumeric()) # True
# 全角ローマ数字
print("Ⅳ".isdigit()) # False
print("Ⅳ".isdecimal()) # False
print("Ⅳ".isnumeric()) # True

Filed Under: python3

  • « Go to Previous Page
  • Page 1
  • Interim pages omitted …
  • Page 46
  • Page 47
  • Page 48
  • Page 49
  • Page 50
  • Interim pages omitted …
  • Page 55
  • 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