1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

[Python]数値に関して

Last updated at Posted at 2023-06-03

数値に関していろいろ書こうと思います。雑記。

数字の0埋めをする

#数字設定
num = 1

#0埋めする
fill = str(num).zfill(4) #()の中は桁数

#表示する
print(fill) #0001

数値 ⇔ 文字列

☆数値 ⇒ 文字列
#数値を設定
num = 1

#文字列に
mojii = str(num)
☆文字列 ⇒ 数値
#文字列(数)を設定
num = "1"

#数値に
sujii = int(num)

数字を足す

#数値を設定
num = 1
num_2 = 2

#+1する
num += 1
num_2 += 1000

#表示する
print(num) #2
print(num_2) #1001

日付を取得

import datetime

date = datetime.timedelta(hours=9)
JST = datetime.timezone(date, 'JST')
now = datetime.datetime.now(JST)
time = now.strftime('%Y/%m/%d %H:%M')
print(time) #YYYY/mm/dd HH:MM

数値とループ処理

#数字を設定
num = 1

#ループ処理 - 10になるまで繰り返す
while num < 10:
    #処理
    print(num)
    
    #numに+1する
    numm += 1

x秒待機

import time

time.sleep(10) #10秒待機

暇と気力があれば付け足します。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?