[Python] 固定値ループする方法

固定値でのループ

1から10まで固定でループさせたい場合

>>> for i in xrange(1, 10 + 1):
...     print i

1
2
3
4
5
6
7
8
9
10

-Python

関連記事

no image

[Python] 配列をソートさせる方法

配列要素値をソートさせる方法 昇順ソート sortメソッドを使って昇順ソートする。 numbers = [1, 5, 3, 2, 4] numbers.sort() print numbers # [ …

no image

[Python] 現在日時を取得して整形する

現在日時の取得方法 datetime.now()で現在日時を取得する。 from datetime import datetime a = datetime.now() print(a) # 2019 …

no image

[Python] 配列の使い方

Pythonでの配列の使い方メモ。 配列の宣言・要素の追加 配列を宣言 colors = [‘red’, ‘green’] 要素を追加 appendメソッドを使って要素を追加します。 colors = …

no image

[Python] dict(連想配列)の使い方

Pythonでの連想配列(dict)の使い方メモ。 宣言・要素の追加 配列を宣言 color_dict = { ‘red’: ‘赤色’, ‘blue’: ‘青色’, } print color_dic …

no image

[Python] 文字列から数値(数値から文字列)に変換する

文字列→数値に変換 int関数を実行する。 a = int(‘100’) b = int(‘200’) print(a + b) # 300 数値→文字列に変換 str関数を実行する。 a = str …

プログラミング言語