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

歡迎訪問(wèn) 生活随笔!

生活随笔

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

python

从零开始学习python:demo2.3

發(fā)布時(shí)間:2024/10/12 python 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 从零开始学习python:demo2.3 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

字符串拼接+:

first="hello" #將hello賦值給變量first
second="world" #將world賦值給變量second
full=first+“ ”+second #拼接first 空格 second并復(fù)制給full
print(full) #打印full完整的值
--------------------------

hello world

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

示例1:

first="hello"
second="world"
full=first+" "+second
print(full)
print("Baby,"+full.title())

?

拼接后都存儲(chǔ)在一個(gè)變量中:

first="hello"

second="world"

full=first+" "+second

msg="Baby,"+full.title()+"!"

print(msg)

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

制表符\t:不使用表格的情況下在垂直方向按列對(duì)齊文本。

換行符\n

示例:

print("Hello")
print("\tHello")
print("HelloWorld")
print("Hello\nWorld")
print("Lauguages:\n\tPython\n\tJAVA\n\tC++\n\tRuby")

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

Hello
?? ?Hello
HelloWorld
Hello
World
Lauguages:
?? ?Python
?? ?JAVA
?? ?C++
?? ?Ruby

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

刪除字符串末尾空白方法:rstrip()

刪除字符串開(kāi)頭空白方法:lstrip()

同時(shí)刪除字符串開(kāi)頭末尾空白方法:trip()

示例

first=input("請(qǐng)輸入你的名字:")
first=first.rstrip() #直接調(diào)用的話只能暫時(shí)刪除空白,下一次訪問(wèn)first的值時(shí)依然會(huì)有空白,要永久刪除這個(gè)字符的空符號(hào),必須將刪除操作的結(jié)果再存回到變量中

first=first.lstrip()

first=first.strip()

print(first)

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


name=input("請(qǐng)輸入你的名字:")
msg="hello"+" "+name.title()+","+"would you like to learn some Python today?"
print(msg)


作業(yè):

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

name = input("請(qǐng)輸入你的名字:")
msg = "hello"+" "+name.title()+","+"would you like to learn some Python today?"
print(msg)
name = name.title()
print(name)
name = name.upper()
print(name)
name = name.lower()
print(name)

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

請(qǐng)輸入你的名字:sandy shirley
hello Sandy Shirley,would you like to learn some Python today?
Sandy Shirley
SANDY SHIRLEY
sandy shirley

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

?

轉(zhuǎn)載于:https://www.cnblogs.com/sandy32399/p/10535942.html

總結(jié)

以上是生活随笔為你收集整理的从零开始学习python:demo2.3的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

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