-
apple_fruit=10
-
print(apple_fruit)
-
-
condition=1
-
while condition<3:
-
print(condition)
-
condition +=1
-
-
example_list=[1,2,3,4,5,6,7]
-
for i in example_list:
-
print(i)
-
'''
-
Windows里面用Control [来对齐代码
-
MAC OS里面用Commnd [来对齐代码
-
'''
-
-
for i in range(1,4,2):
-
print(i)
-
-
x=1
-
y=2
-
z=3
-
if x>y:
-
print("x is greater than y")
-
'''
-
Python 和C语言一样,if elif else分支语句只会执行第一个满足条件的分支
-
'''
def fun(a,b):
c=a/b
print(c)
fun(1,2)
fun(b=2,a=1)
fun(b=1,a=2)
'''
输出,可以用参数名来明确指定参数的值,可以不按默认顺序赋值
0.5
0.5
2.0
'''
-
text='This is my first test.\nThis is next line.\nThis is last line.'
-
-
my_file=open('01myfile.txt','w')
-
my_file.write(text)
-
my_file.close()
-
-
append_text='\nThis is appended file.'
-
my_file=open('my_file.txt','a')
-
my_file.write(append_text)
-
my_file.close()
-
file=open('01myfile.txt','r')
content1=file.read()
print(content1)
content2=file.readlines()
print(content2)