随笔分类 - python
learning python notes
摘要:class Bird: def __init__(self): self.hungry = True def eat(self): if self.hungry: print('Aaaaah') self.hungry = False else: print('No. thanks')class S
阅读全文
摘要:# 魔法方法class FooBar: def __init__(self, value = 42): self.samevalue = value
阅读全文
摘要:result: 关键参数的厉害地方在于可以在函数中提供默认参数
阅读全文
摘要:result: 记住:字符串,数字, 元组是不可变的,即无法修改的。
阅读全文
摘要:>>> def square(x): ... 'calculates the square of the number x.' ... return x*x ... >>> square.__doc__ 'calculates the square of the number x.' >>> help(square) Help on function square in mod...
阅读全文
摘要:pass python中空代码块是非法的,解决的方法就是在语句块中加上一个pass语句 eval >>> eval("print('hellowrold')")hellowrold
阅读全文
摘要:>>> age = 10 >>> assert 0 ", line 1, in AssertionError >>> assert 0 < age < 11
阅读全文
摘要:x == y x < y x <= y x >= y x != y x is y x is not y x in y x not in y
阅读全文
摘要:int(x [,base ]) 将x转换为一个整数 long(x [,base ]) 将x转换为一个长整数 float(x ) 将x转换到一个浮点数 complex(real [,imag ]) 创建一个复数 str(x ) 将对象 x 转换为字符串 repr(x ) 将对象 x 转换为表达式字符串
阅读全文
浙公网安备 33010602011771号