新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Python程序:復(fù)制字符串
創(chuàng)新互聯(lián)Python教程:

我們提供的服務(wù)有:成都做網(wǎng)站、成都網(wǎng)站建設(shè)、微信公眾號開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認(rèn)證、天山ssl等。為上千余家企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的天山網(wǎng)站制作公司
寫一個 Python 程序,用一個實例將一個字符串復(fù)制到另一個字符串。
Python 程序?qū)⒆址畯?fù)制到另一個示例 1
與其他語言不同,您可以使用等于運算符將一個字符串分配給另一個字符串。或者,您可以從頭到尾切片,并將其保存在另一個字符串中。這個 Python 程序允許用戶輸入任何字符串值。接下來,我們使用上面指定的方法來復(fù)制用戶指定的字符串。
# Python Program to Copy a String
str1 = input("Please Enter Your Own String : ")
str2 = str1
str3 = str1[:]
print("The Final String : Str2 = ", str2)
print("The Final String : Str3 = = ", str3)
Python 字符串復(fù)制輸出
Please Enter Your Own String : Hi Guys
The Final String : Str2 = Hi Guys
The Final String : Str3 = = Hi Guys
Python 復(fù)制字符串示例 2
在這個程序中,我們使用 For 循環(huán)來迭代字符串中的每個字符,并將它們復(fù)制到新的字符串中。
# Python Program to Copy a String
str1 = input("Please Enter Your Own String : ")
str2 = ''
for i in str1:
str2 = str2 + i
print("The Final String : Str2 = ", str2)
Python 字符串復(fù)制示例 3
這個 Python 程序和上面的例子一樣。然而,我們使用帶有范圍的 For 循環(huán)來復(fù)制一個字符串。
# Python Program to Copy a String
str1 = input("Please Enter Your Own String : ")
str2 = ''
for i in range(len(str1)):
str2 = str2 + str1[i]
print("The Final String : Str2 = ", str2)
Python 字符串復(fù)制輸出
Please Enter Your Own String : Python Programs With Examples
The Final String : Str2 = Python Programs With Examples
>>>
Please Enter Your Own String : Hello World
The Final String : Str2 = Hello World 新聞名稱:Python程序:復(fù)制字符串
文章轉(zhuǎn)載:http://m.fisionsoft.com.cn/article/coesigs.html


咨詢
建站咨詢
