基础语法
环境准备
helloWorld
打印helloWorld的多种形式:
print("helloWorld");
print('helloWorld');
print("helloWorld")
print('''helloWorld
!''')
print('''欢迎光临小象奶茶馆\n
!''');print("abc")
错误代码:
print('helloWorld
!')
错误代码
print('''欢迎光临小象奶茶馆\n
!''')print("abc")
可以看出,
1、分号表示一个语句的结束。但是可以不以分号结尾,此时一行就是一个语句,分号可加可不加。
2、和js语言一样,单引号和双引号都可以表示字符串
3、print()方法会换行。
4、三个单引号表示字符串在此行未结束。
基本数据类型
str
格式化:
print("姓名{}这位同学很厉害".format('abc'))
输出
姓名abc这位同学很厉害
int
float
运算符
条件控制语句
if condition1:
print("条件1");
else if condition2:
语句块
else:
print("其他");