未分類

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

c++ で文字列を合成(連結)する方法

c言語では、sprintf 関数を使って文字列を合成(連結)することができる。いっぽう、c++ では、文字列を string で表して「+」演算子で文字列を合成することができる。 例 #include …

no image

c言語で文字をつなげる方法

sprintf 関数を使って、result 変数に文字列 s1 と文字列 s2 を結合した文字列を出力することができる。 例 #include<stdio.h> int main(void) { …

no image

c++ で文字列(string)の長さを取得する方法

length() で取得する。 例 #include <iostream> #include <string> using namespace std; int main () { str …

no image

X(twitter) 時期を指定して検索する方法

X/Twitter の検索窓に次のように打ち込むことで、条件を指定して、絞り込んだポストを表示することができる。 日付を指定する since:2022-02-22 until:2022-02-23 あ …