目录
前言
脚本运行在CentOS 7环境下的,请知晓!!!学习一门语言,最好的方法就是多敲!!!
-
01-hello world!
#!/usr/local/bin/python3 #解释器的环境变量
print('hello world')
print("hello world") #python中的单双引号没区别
if 3 < 0: #判断语句时,要加分号:
print('ok')
print('123') #判断语句下的语句缩进表示以属于if 3<0判断语句的,3<0不生效,包含的语句不执行
print('no') #正常输出,此语句不缩进,表示不属于if 3<0判断语句的
if 3 > 0:
print('Today is Tuesday!') #3>0条件成功,此语句正常输出
x = 3 ; y = 4 #不推荐,建议写成两行
print(x + y) #输出x+y的和
a = 8
b = 8
print(a+b)
01-hello world!运行的结果为:
hello world
no
Today is Tuesday!
7
16
-
02-print
#!/usr/local/bin/python3
print('--字符串空格--')
print('hello world!') #字符串也包含“ ”空格
print('hello','world!') #逗号用于空格字符串间的
print() #表示空一行
print('--字符串拼接--')
print('hello''world!') #字符串间默认拼接
print('hello'+'world!') #加号用于字符串间拼接
print()
print('--print中\\n换行--') #用\n前用\表示转义
print('abc')
print('a\nb\nc')
print('----------') #表示分隔符
print('--print中*的用法--')
print('3' * 5) #print中字符用*号表示字符重复多少次
print(3 * 5) #print中数字用*号表示求积算法
print('----------')
print('--print中end的用法--')
print('Nothing is impossible to a willing heart!') #字符默认是换行的
print('Nothing is impossible to a willing heart!', end='') #end=''表示不换行,单引号内没有空格的
print('Nothing is impossible to a willing heart!', end='\n') #end='\n'和\n都是换行
print('----------')
print('--print中的sep表示两单词间用什么字符分隔--