#print("hello world",flush=True)
print("test print!!!",end=" ")
print("no wrap")
flush代表刷新缓冲区
end" " 代表去空格
print("string "," string 2" ,1003,sep=",")
sep指定用什么分割
print("error out",file=sys.stderr)
logf=open("log.txt","a")
print("Log to file ",file=logf)
logf.close()
csv=open("python.csv","a")
print("名称","数量","内容",sep=",",file=csv)
print("name1","1","1111",sep=",",file=csv)
print("name2","2","2222",sep=",",file=csv)
csv.close()
num = 1+2j
print(num.imag)
print(num.real)
num=complex(1,2)
print(num)
print(type(num))
print(id(num))
print("test string")
str1="test strinq001"
print(str1)
print(type(str1))
print(id(str1))
print(str1[2])
print(str1[3])
str1="0123456"
print(str1[3:6])
print(str1[-3:-1])
print(str1[1])
str[-1]=6;
负数表示从结尾开始。
print(r"DDDD\t\ssfsa")
a="aaaaaaaa"\
"bbbbbbbbb"\
"ccccccccc"
print(a)
a=("aaaaaaaa\
bbbbbb\
cccccc"
)
print(a)
a="""
aaaaaaaaa
BBBBBBBBB
CCCCCCCCc
"""
print(a)
‘’‘
代表注释
‘’’
str1="xxx"
str2="yyy"
str3=str1+str2;
print(str3)
str1="xxx"
str2="yyy"
str3=str1+str2;
print(str3)
s="格式化字符串 %s %d %c %f " % ("teststr",200,str1[0],1.0)
print(s)
print(len(s))
汉字和英文都是一个字节
指向不能更改其余和list相似
tuple = ("str1","str2")
#元祖指向不可改变
try:
tuple[0]="000"
except TypeError:
print("元祖指向不可改变")
#元祖指向的值可以改
tup = ("str1","str2",1,[1,2,3])
tup[3][0]=100
print(tup)
#dictionary 初始化
dic={"name": "python",
"year": 1991,
"ver": 3.7,
4: 5,
"keys" : ["print","for"]
}
print(dic)
dic[4]=6
dic["src"]="c"
print(dic)
dic.pop("keys")
print(dic)
dic.clear()
try:
print(dic["name"])
print(dic["arg"])
except KeyError:
print("dic KeyError")
if "year" in dic:
print("key year")