1、关于输出(print函数)
#格式化输出
#%s为字符串格式,%d整数格式,%f浮点数格式(默认保留6位小数),其中.2表示保留两位小数点。
#如果想输出%,则需要用两个%号,即print("%%"),否则会报错。
name = "Jack"
tall = 185.5
weight = 90
print("这个人的姓名为%s,身高为%.2f厘米,体重为:%d公斤"%(name,tall,weight))
#格式化输出在变量前也可以不用%,而用format函数,但是此时要将输出字符串中的格式化符号换为{},在format前加点。
print("这个人的姓名为{},身高为{}厘米,体重为:{}公斤".format(name,tall,weight))
#无换行输出
#print函数默认为带换行符输出,如果想不带换行符输出则用如下:
print("hello",end="")
print("world") #输出:helloworld
2、列表及列表、元组相关函数(Sequence Types OR Text Sequence Type)
"""
split函数
格式:split(sep=None,maxsplit=-1)
description:Return a list of the words in the string,using sep as the delimiter
string(以sep为分隔符将一个字符串分割为多个字符串组成的列表).If maxsplit is given,at most
maxsplit splits are done(thus,the list will have at most maxsplit+1 elements)(若
指定maxsplit,则字符串会被分成maxsplit+1个子串).If maxsplit is not specified or -1,then
there is no limit on the number of splits(all possible splits are made).(maxsplit为
分隔次数,若不指定maxsplit或者指定为-1,则按照sep为分隔符将字符串全部分隔)
If sep is given, consecutive delimiters are not grouped together and are deemed to
delimit empty strings (for example, '1,,2'.split(',') returns ['1', '', '2'])(若不指
定sep则默认以空格作为分隔符,字符串中间的空格项会自动忽略。若是指定了分隔符,则空格就不会被当成分隔
符,中间的空格项不会忽略). The sep argument may consist of multiple characters (for
example, '1<>2<>3'.split('<>') returns ['1', '2', '3'])(支持多个字符组成字符串作为分隔
符). Splitting an empty string with a specified separator returns [''].
If sep is not specified or is None, a different splitting algorithm is applied:
runs of consecutive whitespace are regarded as a single separator(sep没有被指定,则多
个连续空格会被当做单个分隔符), and the result will contain no empty strings at the
start or end if the string has leading or trailing whitespace. Consequently,
splitting an empty string or a string consisting of just whitespace with a None
separator returns [].
"""
'1,2,3'.split(',') #['1', '2', '3']
'1,2,3'.split(',', maxsplit=1) #['1', '2,3']
'1,2,,3,'.split(',') #['1', '2', '', '3', '']
'1 2 3'.split() #['1', '2', '3']
'1 2 3'.split(maxsplit=1) #['1', '2 3']
' 1 2 3 '.split() #['1', '2', '3']
3.os.path相关函数