2000字范文,分享全网优秀范文,学习好帮手!
2000字范文 > Python入门 [输出 注释 列表 元祖 集合 字典 if while for]

Python入门 [输出 注释 列表 元祖 集合 字典 if while for]

时间:2023-01-11 10:00:33

相关推荐

Python入门 [输出 注释 列表 元祖 集合 字典 if while for]

print("Hello Python") #输出

'''多行注释 用 三个引号

'''

a=1 #赋值 变量首字母只能书字母下划线 第二个字符数字,字母,下划线

声明一个列表 [ ]

abc=["My","You"]abc[0]# 'My'abc[1] = "He" #替换列表中的元素

定义一个元祖 ()

cde = ("My","You")cde[0]

列表中的元素可以修改 元祖不能修改

集合 set 集合中的元素不能重复,两个集合的交集

a="sajdlkjasj"b="ajsklaanmslkd"sa = set(a) #集合sb = set(b)sa&sb #取两个字符串交集sa|sb #取并集

字典 {key:value,key2:value2}

d1={"name":"zy","sex":"man"}d1["name"] #zyd1["sex"] #man

if

a=1if(a>7): # if a>7 if+空格+条件print("a>7")elif(a<2):print("a<2")else:print("nnn")

while

a=0while a<8:print("hello")a+=1

for

a=["a","c","d"]for i in a:print(i)for i in range(0,10): #输出0,1,2,3,4,5,6,7,8,9 一共10个数print(i)

break中止当前循环语句 continue中止一次

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。