日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

python中a=str(int(a))什么意思_如何解决TypeError:只能将str(而不是“int”)连接到str - python...

發(fā)布時(shí)間:2025/3/13 python 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python中a=str(int(a))什么意思_如何解决TypeError:只能将str(而不是“int”)连接到str - python... 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

我決定為進(jìn)行Unicode測試而制作某種秘密代碼。

我已經(jīng)通過在Unicode中添加數(shù)字來做到這一點(diǎn),所以這將是一個(gè)秘密。

我一直收到此錯(cuò)誤,但我不知道如何解決。

有什么解決方案嗎?

原始碼

message = input("Enter a message you want to be revealed: ")

secret_string = ""

for char in message:

secret_string += str(chr(char + 7429146))

print("Revealed", secret_string)

q = input("")

原始錯(cuò)誤

---------------------------------------------------------------------------

TypeError Traceback (most recent call last)

in

2 secret_string = ""

3 for char in message:

----> 4 secret_string += str(chr(char + 7429146))

5 print("Revealed", secret_string)

6 q = input("")

TypeError: can only concatenate str (not "int") to str

更新的代碼

while True:

try:

message = int(input("Enter a message you want to be decrypt: "))

break

except ValueError:

print("Error, it must be an integer")

secret_string = ""

for char in message:

secret_string += chr(ord(char - str(742146)))

print("Decrypted", secret_string)

q = input("")

參考方案

Python的工作方式與JavaScript稍有不同,例如,您要串聯(lián)的值必須是同一類型,即int或str ...

因此,例如下面的代碼拋出一個(gè)錯(cuò)誤:

print( "Alireza" + 1980)

像這樣:

Traceback (most recent call last):

File "", line 1, in

print( "Alireza" + 1980)

TypeError: can only concatenate str (not "int") to str

要解決此問題,只需將str添加到您的數(shù)字或值中,例如:

print( "Alireza" + str(1980))

結(jié)果為:

Alireza1980

Python uuid4,如何限制唯一字符的長度 - python

在Python中,我正在使用uuid4()方法創(chuàng)建唯一的字符集。但是我找不到將其限制為10或8個(gè)字符的方法。有什么辦法嗎?uuid4()ffc69c1b-9d87-4c19-8dac-c09ca857e3fc謝謝。 參考方案 嘗試:x = uuid4() str(x)[:8] 輸出:"ffc69c1b" Is there a way to…Python-如何檢查Redis服務(wù)器是否可用 - python

我正在開發(fā)用于訪問Redis Server的Python服務(wù)(類)。我想知道如何檢查Redis Server是否正在運(yùn)行。而且如果某種原因我無法連接到它。這是我的代碼的一部分import redis rs = redis.Redis("localhost") print rs 它打印以下內(nèi)容

我正在嘗試在Linux OS(CentOS 7)上使用Python-crontab模塊我的配置文件如下:{ "ossConfigurationData": { "work1": [ { "cronInterval": "0 0 0 1 1 ?", "attribute&…Python:檢查是否存在維基百科文章 - python

我試圖弄清楚如何檢查Wikipedia文章是否存在。例如,https://en.wikipedia.org/wiki/Food 存在,但是https://en.wikipedia.org/wiki/Fod 不會(huì),頁面只是說:“維基百科沒有此名稱的文章。”謝謝! 參考方案 >>> import urllib >>> prin…Python Pandas導(dǎo)出數(shù)據(jù) - python

我正在使用python pandas處理一些數(shù)據(jù)。我已使用以下代碼將數(shù)據(jù)導(dǎo)出到excel文件。writer = pd.ExcelWriter('Data.xlsx'); wrong_data.to_excel(writer,"Names which are wrong", index = False); writer.…

總結(jié)

以上是生活随笔為你收集整理的python中a=str(int(a))什么意思_如何解决TypeError:只能将str(而不是“int”)连接到str - python...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。