学习Python第一天!(2)

学习Python


复数(real+imagj)

带后缀j或J是虚数,使用complex(real,imag)函数可以创建

>>> complex(2,3)

(2+3j)

使用real,imag提取实部,虚部

>>> a=complex(2,3)

>>> a.real

2.0

>>> a.imag

3.0


字符串

字符串可以由+操作符号连接,使用*重复次数

>>> A='ni'+'hao'

>>> A

'nihao'

>>> '<'+A*10+'>'

'<nihaonihaonihaonihaonihaonihaonihaonihaonihaonihao>'

内置函数len()返回字符串长度

>>> len(A)

5

你可能感兴趣的:(字符串,Complex)