语言元素
1.变量这个就注意命名规范,字幕数字下划线,驼峰命名更好看
2.python 中的变量的类型是不敏感的,最好命名的时候带上类型,整型,浮点,字符串,布尔,复数
3.实操
a = int(input('a = '))
b = int(input('b = '))
print(a / b)
print(a // b)
print(a % b)
print(a ** b)
a = 100
b = 12.345
c = 1 + 5j
d = 'hello, world'
e = True
print(type(a))
Str_a = str(type(a))
if 'int' in Str_a:
print('a is a int type')
else:
print('a is not a int type')
print(type(b))
print(type(c))
print(type(d))
print(type(e))
print(ord('a'))
print(int('100',10))
print(int('100',16))
print(int('100',8))
print(int('100',2))
**结果: **
a = 25
b = 2
12.5
12
1
625
<class 'int'>
a is a int type
<class 'float'>
<class 'complex'>
<class 'str'>
<class 'bool'>
97
100
256
64
4
上面包含了输入,类型判断,子串包含判断,str()类型强转和if语句
4.下面放点东东
强转的
int()
:将一个数值或字符串转换成整数,可以指定进制。float()
:将一个字符串转换成浮点数。str()
:将指定的对象转换成字符串形式,可以指定编码。chr()
:将整数转换成该编码对应的字符串(一个字符)。ord()
:将字符串(一个字符)转换成对应的编码(整数)。
运算符
运算符 | 描述 |
---|---|
[] [:]
|
下标,切片 |
** |
指数 |
~ + -
|
按位取反, 正负号 |
* / % //
|
乘,除,模,整除 |
+ -
|
加,减 |
>> <<
|
右移,左移 |
& |
按位与 |
^ |
|
按位异或,按位或 |
<= < > >=
|
小于等于,小于,大于,大于等于 |
== !=
|
等于,不等于 |
is is not
|
身份运算符 |
in not in
|
成员运算符 |
not or and
|
逻辑运算符 |
= += -= *= /= %= //= **= &= |= ^= >>= <<=
|
(复合)赋值运算符 |
文集传送门 学习python100天
整个学习python100天的目录传送门
无敌分割线
再最后面附上大神的链接传送门