未分類

python3 で、文字列の末尾の文字を削除する方法

投稿日:

[:-1] で、最後の文字を取り除いた文字列を取得することができる。

str1 = "こんにちは。"
result = str1[:-1]
print(result)

結果

こんにちは

-未分類

執筆者:


comment

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

関連記事

no image

tex で期待値記号を入力する方法

\mathbf を使う。 例 $\mathbf{E}(\xi)$ 結果

no image

python3 でカンマの入った数値の文字列を数値に変換する方法

replace と int 変換を組み合わせる。 例 str1 = ‘1,234,567’ int1 = int(str1.replace(‘,’,”)) print(int1) 結果 123456 …

no image

tex で href の色を変更する方法

例で、urlcolor=red と書けば、「link to google」の文字列は赤色(red)になる。 もし urlcolor=blue と書けば、リンクは青色になる。 例 \usepackage …

no image

tex で方程式を文書の中央揃えにする(eqnarray→ align)

amsmath パッケージを使ったうえで、align を使う。次の例では eqnarray の代わりに、align を使っている。 例 \usepackage {amsmath}  \begin{do …

no image

tex の表で、複数行を1行内に入れる方法

multirow パッケージを使っておき、表内で multirow で入力する。 例 \usepackage{multirow} \begin{document} \begin{table} \beg …