07_位运算符[扩展]
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556# 位运算符(了解)# & 位与, | 位或, ~ 位非, ^位异或, >> 右移, << 左移# &print(10 & 9)'''10 => 10109 => 1001-------------8 <= 1000'''# |print(10 | 9)'''10 => 10109 => 1001-------------11 <= 1011'''# ~print(~10) # -11'''00000000 00000000 00000000 0000101011111111 11111111 11111111 11110101 补码 (了解) ...
06_成员运算符和身份运算符
1234567891011121314151617181920# 成员运算符# in, not inages = [1, 2, 3, 4]print(1 in ages) # Trueprint(33 not in ages) # True# print(not 33 in ages) # True# 身份运算符# 判断内存地址# is, is nota = 10b = aprint(id(a)) # 1501996416print(id(b)) # 1501996416print(a is b) # Trueprint(a is not b) # False
05_逻辑运算符
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990# 逻辑运算符# and与, or或, not非# and 与# and的两边都为真,则结果为真, 否则为假print(True and True) # Trueprint(True and False) # Falseprint(False and True) # Falseprint(False and False) # Falseprint(3>4 and 4<5) # False# or 或# or的两边都为假,则结果为假,否则为真print(True or True) # Trueprint(True or False) # Trueprint(False or True) # Trueprint(False ...
04_关系运算符
1234567891011121314151617181920212223# 关系运算符# >, >=, <, <=, ==, !=print(10 > 3) # Trueprint(10 >= 3) # Trueprint(10 < 3) # Falseprint(10 <= 3) # Falseprint(10 == 3) # Falseprint(10 != 3) # Trueprint(3 == 3) # Trueprint(3 == '3') # Falseprint(3 != '3') # True# 字符串比较# ASCII码# A~Z: 65~90# a~z: 97~122# 0~9: 48~57print('a' > 'b') # Falseprint('A' > 'a') # Falseprint('abcde' < ...
03_算术运算符和赋值运算符
123456789101112131415161718192021222324252627282930# 算术运算符: +, -, *, /, %, **, //print(10 + 3)print("10" + "3") # "103",字符串拼接print("10" + str(3)) # 不同类型不可以相加+print(10 - 3)print(10 * 3)print(10 / 3) # 3.3333333333333335print(10 % 3) # 1print(10 ** 3) # 1000print(10 // 3) # 3# 赋值运算符# =# +=, -=, *=,...n = 100# 将n自身的值加1# =赋值运算符: 先运算=号右边的表达式n = n + 1print(n) # 101n += 1 # 等价于:n=n+1print(n) # 102
02_占位符
12345678910111213141516171819202122name = "渣渣辉"age = 50# s = "你好, 渣渣辉, 年龄50, 在贪玩蓝月中等你来砍"# %s: 字符串# %d: 整数# %f: 小数# s = "你好, %s, 年龄%d, 在贪玩蓝月中等你来砍" % (name, age)s = "你好, 古天乐, 年龄%f, 在贪玩蓝月中等你来砍" % ages = "你好, 古天乐, 年龄%.2f, 在贪玩蓝月中等你来砍" % age # 保留2个小数# formats = "你好, {}, 年龄{}, 在贪玩蓝月中等你来砍".format(name, age)s = "你好, {n}, 年龄{a}, 在贪玩蓝月中等你来砍".format(a=age, n=name)# f-string: python3.6及以上s = f" ...
01_数据类型
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657''' 数据类型: Number: int 整数 float 小数,浮点数 String: 字符串, "hello", 'hello' Boolean: 布尔类型, True, False List: 列表, [1,2,3] Tuple: 元组, (1,2,3) Dict: 字典, {"name": "蔡徐坤"} Set: 集合(了解), {1,2,3} Bytes: 二进制, b'hello' None: 空值类型, None'''# Python是弱类型语言a = 10print(type(a)) ...
Python练习1
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768# 1.# 熟练使用常用DOS命令行进行操作, cd## 2.# 自己安装Python开发环境并清楚配置环境变量的目的## 3.# 写一个初级程序# 打印:大家好,我是XXXprint("大家好, 我的杨超越")# 4.# 在控制台打印出古诗如下所示的格式:# 春眠不觉晓,# 处处闻啼鸟。# 夜来风雨声,# 花落知多少。print("春眠不觉晓,", end='')print("处处闻啼鸟。", end='\n')print('''春眠不觉晓,处处闻啼鸟。夜来风雨声,花落知多少。''')# 5.# 控制台打印出如下格式所示的内容# ** ** ** ** ** ** *# 欢迎学 ...
03_输入和输出
123456789101112131415161718192021222324252627282930313233343536# 输出x = 3y = 4print("x+y=", x+y)# 输入# input: 会等待用户输入# input()# n = int(input("请输入您的真实年龄:"))# print(n)# print(n + 1)# ctrl + / : 快速添加或者取消注释# death_age = 100# age = input('请输入您的年龄:')## print(death_age - int(age))# int(): 转换成整数# float(): 转换成小数# str() : 转换成字符串print(int(3.8)) # 3print(int("5")) # 5# print(int("5.2")) # 报错print(int(float("5.2"))) # 5print(str(10)) # "10& ...
02_变量
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152# 变量: 可以改变的量# 定义变量/声明变量x = 10print(x)y = 3print(x * y)y = "hello"print(y)x = y = 1print(x, y)x, y = 2, 3print(x, y) # 2 3# 交互2个变量的值x, y = y, xprint(x, y) # 3 2# 删除变量z = 1print(z) # 1# del z# print(z)# 关键字import keywordprint(keyword.kwlist)'''[ 'False', 'None', 'True', 'and', 'as', 'assert', 'break', ...