0
1

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 3 years have passed since last update.

Python文法総復習

Last updated at Posted at 2020-05-20

#目的
HackerRankをやりながら忘れそうな文法を記載していきます。

####標準入力をint型で取得してリスト化

sample.py
# 標準入力 1 2 3 4 5
ar = list(map(int, input().rstrip().split()))

rstrip()は末端¥nを削除

####for文

sample.py
for i in iterableな値
 print(i)

iterableとは、listやtaple、range()など一要素ずつ取り出せるもの。
len(array)などのintは不可。

####文字の繰り返し

sample.py
string='A'*3
print(string)
# 出力 AAA

####長さの決まった文字列の分割

sample.py
# 入力 12:10:10PM
time=s[:8]
str=s[8:]
#time 12:10:10
#str PM

####if複数条件

sample.py
if(A and B)
if(A or B)

####listへの挿入

sample.py
#末尾に挿入
list.append(入れたいもの)

#指定の位置に挿入
list.insert(index, 入れたいもの)

####文字列の結合

sample.py
'入れたいもの'.join(list)

####絶対値

abs(x-y)
0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?