24大数据 9.18 3-2 基础语法
·
9.18 3-2 基础语法
"""
3-2
标识符
1.第一个字符必须以字母或下划线_组成
2.标识符的其他部分由字母、数字、下划线组成
3.标识符大小写敏感,M1和m1是不同的标识符
4.标识符对长度无硬性限制,但一般不超过20个字符,尽量保持简洁
5.避免和关键字同名,如if、for、while
例子:
1_num(x) num_1(√) while(x)
age=25 nianling=25 nl=25
python的保留关键字:
False True None and as assert await break continue
class def del if elif else for from import in is
lambda not or pass return try while try yield
finally except global nonlocal raise
单行注释 #
多行注释
''' '''
""" """
缩进
缩进空格数可变,但是同一个代码块语句必须使用相同的缩进空格数
通过制表键tab键来控制缩进
print()
多行语句
1.Python通过反斜杠\来实现多行语句
2.在[],{},()中的多行语句,不需要通过反斜杠\来实现多行语句
例子:
total = one+two+three
total = one+\
two+\
three
total = ['one','two','three']
total = ['one',
'two',
'three']
python基本数据类型
等号(=) 用来给变量赋值,把=右边的值赋值给=左边的变量
相等(==) 表示是否相等
不相等(!=) 表示不相等
整型变量 int
浮点数(小数)变量 float
字符串变量 str
布尔类型 bool True(1) 为真 False(0) 为假
total = 100 #整型变量
miles = 800.0 #浮点型变量
name = "Alice" #字符串变量
多变量赋值
1.同时给多个变量赋值(同一个值)
a = b = c = 1
2.同时给多个变量赋不同类型的值
a, b, c = 1, 2.5, "Alice"
查看数据类型 type()
print(type(a))
"""
a, b, c = 1, 2.5, "Alice"
print(type(c))
# 数值运算
# + - *
# / 得到的是浮点数
# // 得到的一个整数,向下取整
# % 取余,得到除法的余数
print(37//2) #18
print(49%3) #1
print(2**6) #64
更多推荐


所有评论(0)