未分類

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

投稿日:

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

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

結果

こんにちは

-未分類

執筆者:


comment

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

関連記事

no image

tex で、表のキャプション内で改行する方法

\newline を使って次のように書く。 例 \begin{table} \begin{tabular}{ |c|c|c|c| } \hline 1 & 2 & 3 \\ \hlin …

no image

python3 で辞書(dict) の for ループでキーと値を取得する

キーと値を取得するには次のようにする。キーは dict のループ、値は dict の values() のループで取得できる。 例 mydictionary = {‘color’: ‘白’, ‘ani …

no image

matplotlib で縦横の罫線を出力する

罫線を出力するには、pyplot.grid を使う。 例 import numpy as np import matplotlib.pyplot as plt x = np.linspace(0, 2 …

no image

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

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

no image

tex と分数

tex で分数を入力するには、frac を使います。 \frac{2}{3} 表示結果 次のように表示されてしまう場合は、バッククォート(\ マーク)が抜けているのが原因です。 間違った場合。