日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

从零开始学习python:demo2.3

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

字符串拼接+:

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

hello world

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

示例1:

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

?

拼接后都存儲在一個變量中:

first="hello"

second="world"

full=first+" "+second

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

print(msg)

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

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

換行符\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()

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

同時刪除字符串開頭末尾空白方法:trip()

示例

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

first=first.lstrip()

first=first.strip()

print(first)

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


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


作業(yè):

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

name = input("請輸入你的名字:")
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)

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

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

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

?

轉載于:https://www.cnblogs.com/sandy32399/p/10535942.html

總結

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

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