Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/sinat_29006909/article/details/91355912
We all know that not every programming language syntax is the same, so learn a new programming language, the time to master the grammar in order to allow developers to fill the gap.
Here comes the basis of learning Python editor IDLE ** (After installing the menu bar you can directly search IDLE) **
1.输出
print("Hello Wrold!")
2.注释
#单行注释
'''
多行注释
'''
3.数据类型
字符串
a = "string"
b = 'string'
c = '''string'''
数字
d = 4
列表
e = [2,'f','list']
f = ['2','f',[5,'f']]
元组tuple(元组中的数据是不能修改的)
g = (8,'4','tuple')
h = (6,'new',['4','fs','list'])
但元组h中的['4','fs','list']的内容是可以修改的
字典
{键:值,键:值}
i={"name":"lisa","sex":"female","age":18}
集合set(去除重复)
j = set("abcbcdeafgf")
print(j)会显示
{'d', 'b', 'c', 'f', 'a', 'e', 'g'}会把里面重复的项去除掉
if语句
a = 1
b = 2
if(a>b):
print(a)
elif(a<b):
print(b)
else:
print("两数相等")
while语句
i = 0
while(i>5):
print(i)
i+=1
for语句
list = [9,3,"s","n"]
for i in list:
print(i)
#for从0到10
for i in range(0,10):
print(i)
#for从10到0
for i in range(10,0,-1):
print(i)
循环中break,continue也是有效的
These are the basic syntax of Python