python基础

python基础

https://www.python.org/downloads

import this
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!

变量:x, y = 3, 5
字符串:” “” 都是字符串 转义字符\ \n换行

print(r”dafsg”) 加入r是原始字符,里面的转义没有用。长字符串:一行写不下后面加入\ ,“”” 长文本“””
print(‘你好’ * 30)

< <= > >= == != is is not

counts = 3
while counts > 0:
    temp = input('猜一个数字:')
    guss = int(temp)

    if guss == 8:
        print('yes')
        break
    else:
        if guss > 8:
            print('大了')
        else:
            print('小了')
    counts = counts - 1

print('结束')
import random
# 打印一个随机数:
print(random.random())
# 捕获状态:
state = random.getstate()
# 打印另一个随机数:
print(random.random())
# 恢复状态:
random.setstate(state)
# 下一个随机数应该与捕获状态时相同:
print(random.random())

浮点数:不是百分比精确,做比较要小心使用 decimal.Decimal(‘0.1’) ,5e-05=0.00005
复数:

// 向下取整
% 取余 divmod(3,2)
abs() 绝对值
int() float() pow(2, 3)2的3次方

bool(False) bool(0)

逻辑运算符:and or not
短路逻辑:从左往右,只有当第一个操作数的值无法确定逻辑运算的几个时,才对第二个操作数进行求值
3 and 4是4 之后3 or 4 是3
运算符优先级:先执行较高

python

pip

2025-6-28 17:02:02

学习战法股票

题材细分,看盘界面

2025-7-20 15:19:37

搜索