中綴表示式(算數表示式)轉成字尾表示式(逆波蘭表示式)並求計算值
阿新 • • 發佈:2021-01-28
刪除變數
name = "alex"
print(name)
del name
print(name)
結果圖
name = "Alex"
name2 = name
print(name)
print(name2)
print(id(name))
print(id(name2))
name = "Jack"
print(name)
print(name2)
name指向Jack
name2指向Alex
資料型別
age_alex = 26
alex_salary = 2000
type (age_alex)
type(alex_salary)
print(type(age_alex) )
print(type(alex_salary) )
字元型
age = 22
age2 = "22"
print(type(age) )
print(type(age2) )#只有是字元才要加引號
float(浮點型)
print(type(2.32))
print(type(-3.14))
字串 在Python中加了引號的字串都被認為是字串
name = "Alex Li"
age = "22"
msg = '''My name is Alex,I am 22'''
hometown = 'shandong'
因為有單引號所以需要雙引號
msg = "My name is Alex,I'm 22 "
多引號 多引號的作用就是多行字串必須用多引號
msg = '''
今天我寫首詩
真好
'''
msg = """
今天我寫首詩
真好
"""
print(msg)
大小寫
print(msg.upper())
print(msg.lower())
msg1 = msg.upper()#想要儲存還需要賦值
MY NAME IS ALEX,I AM 22
my name is alex,i am 22
print(name.center(50,"-"))#50是50個位元組
---------------------Alex Li----------------------
字元相加,相乘
name = "alex"
hometown = "usa"
print(name+hometown)
print(name*2)
alexusa
alexalex
列表
names = []
print(type(names))
<class ‘list’>
names = ["Alex","Jack","Rain","wusir","bk"]
print(names)
[‘Alex’, ‘Jack’, ‘Rain’, ‘wusir’, ‘bk’]
names[0]
‘Alex’
names[4]
‘bk’
更改
names = ["Alex","Jack","Rain","wusir","bk"]
names[4] = "黑"
print(names)
[‘Alex’, ‘Jack’, ‘Rain’, ‘wusir’, ‘黑’]
在0,1,2,3,4的4前面插入
names.insert(4,"金角大王")
print(names)
在列表後面
names.append("金大王")#在列表後面
print(names)
[‘Alex’, ‘Jack’, ‘Rain’, ‘wusir’, ‘金角大王’, ‘黑’, ‘金大王’]
刪除4
del names[4]
print(names)
[‘Alex’, ‘Jack’, ‘Rain’, ‘wusir’, ‘黑’, ‘金大王’]
他只是從左向右刪除找刪除一個Alex
names = ["Alex","Jack","Rain","wusir","bk","Alex"]
names.remove("Alex")
print(names)#他只是從左向右刪除找刪除一個Alex
[‘Jack’, ‘Rain’, ‘wusir’, ‘bk’, ‘Alex’]
查詢
"rain" in names#查詢
False
"Rain" in names
True
輸出10行金角大王
a = """
金角大王"""
print(a*10)
在末尾插入Alex
names = ["Alex","Jack","Rain","wusir","me"]
names.append("Alex")
print(names)
[‘Alex’, ‘Jack’, ‘Rain’, ‘wusir’, ‘me’, ‘Alex’]
刪除我的me最後在結尾加上
names.remove("me")
names.append("me")
print(names)
[‘Alex’, ‘Jack’, ‘Rain’, ‘wusir’, ‘Alex’, ‘me’]