数据类型
浮点:1.23e9=-0.=0.12e-7整数中间可以加横线:=10-000-000字符用''或””分割。如果是单引号,可以“‘”或者’\‘’\是普通的转意,通用。r''可以不转义(r'Thisisatest\',Yes!'):Thisisatest\',Yes!如果不好阅读'''...'''也可以。('''......''')布尔And:(53and57)_TureNot:not12Trueage=3ifage=10:('\n')else:('\n')3.
,,,,,?,,,
支持
和UTF-8的关联,计算机系统通用的字符编码工作方式:在计算机内存中,统一使用编码,当需要保存到硬盘或者需要传输的时候,就转换为UTF-8编码。获得长度的函数islen()
(len('')):9
(len('训养')).:2.
Thisistheofthestris..
Ifyouwanttohavetheofthe,thendoasthis:
(len(b'Joe')):3
(len(b'\xe5\x82\xbb\xe9\x90\xbc')).:6
(len('**'.('utf-8'))).:6
List
[]to:
=['Rob','','']
('Myare:')
()
输出:
Myare:
['Rob','',‘']
好像不是想要的
可以用下标获得内容。
([2])
长度函数:len
len()列表的元素数量
len()-1:最后一个的下标。
([len()-1])
(len()-1)
[len()-1]=[-1]:最后一个元素
toaddanewtothelist:
.(‘’)
(,)
Toanintothelistto
.(2,’Ken')
Pop()
Tothelast
.pop()
pop(i)
Toith
.pop(2)
Thelist.Itsbeonceitis.(()to)
=(M1,M2,M3)
Iftheonlyisa,itbesetas:
=(3,):
itwillbeasthe3ofa.
:
If:
The..
Elif:
The
Else:
Whatitwillbe.
('HowOldareyou?')
age=()
ifage=40:
('youare',age,'old.Youmustbe')
('Butyouhavelotsof.')
elifage=41:
('No,youhaveinyourlife')
else:
("youare",age,"old.Youareasgoodasdead.”)
:
For…in…
('Myinfor--inloopare:')
forin:
()
#toadd1-10
sum=0
foriin(1,2,3,4,5,6,7,8,9,10):
sum=sum+i
('Now,timetoshowthe,1++10is:')
(sum)
willalistof.
(101):will1…100
sum=0
foriin(101):
#(i)
sum=sum+i
('Now,timetoshowthe,1++100is:')
(sum)
====5050
loop:
Totheeven100:
('Theofeven0-100is:')
sum=0
=100
:
sum=sum+
=-2
(sum)
==2550
('Theofodd0-100is:')
sum=0
=99
:
sum=sum+
=-2
(sum)
===2500
inaloop:
('Totheofinaloop')
('Theofodd0-100is:')
sum=0
=100
:
=-1
if%2==0: