Python02
1输入2个数字,计算a的b次方,存到一个变量中,使用模板字符串打印
1)读入两次,存到两个变量里面:input
2)int转成整数
3)pow(a,b)
4)result=pow(a,b)
5)模板字符串%s
num1=int(input("请输入第一个数字: ”))
num2=int(input("请输入第二个数字: “))
result=pow(num1,num2)
print("%s的%s次幂的计算结果是%s")%(num1,num2,result)
2.逻辑运算啥时候是False
0,False,空的数据结构: [],(),{},set([]),None
3.
>>> s='ab"c'
>>> s
'ab"c'
>>> "he's a men"
"he's a men"
>>> l=[1,2,3]
>>> type(l)
<class 'list'>
>>> t=(1,2,3)
>>> type(t)
<class 'tuple'>
>>> d={1:2,"a":"b"}
>>> print(d)
{1: 2, 'a': 'b'}
>>> print("hello")
hello
>>> print("hello!",end="***")
hello!***>>>
>>> print("hello world!",end=" ")
hello world! >>>
>>> s=input("请输入一个内容: ")
请输入一个内容: test1test2test3
>>> for i in range(3):
... print(s,end="")
...
test1test2test3test1test2test3test1test2test3>>>
>>> num=input("请输入一个数字: ")
请输入一个数字: 100
>>> num*2
'100100'
>>> int(num)
100
>>> type(int(num))
<class 'int'>
>>> int(num)*2
200
>>> float(num)
100.0
>>> float("1.23")
1.23
>>> str(1)
'1'
>>> str(1.1)
'1.1'
>>> int(-1)
-1
>>> "%s is a man"%'Mike'
'Mike is a man'
>>> print("%s is a man"%'milk')
milk is a man
>>> import math
>>> math.floor(2.9)
2
>>> math.ceil(2.1)
3
>>> "{1}{0}{1}".format("hello","world")
'worldhelloworld'
>>> "{1} {0} ".format("hello","world")
'world hello '
>>> print("{name} is a good man".format(name='Milk'))
Milk is a good man
>>> round(1.1)
1
>>> rount(1.5)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'rount' is not defined
>>> round(1.5)
2
>>> round(1.4)
1
>>> round(2.5)
2
>>> round(9.5)
10
>>> round(8.5444332,2)
8.54
>>> import math
>>> math.sqrt(4)
2.0
>>> math.sqrt(1.414)
1.18911731969558
>>> math.pow(2,3)
8.0
>>> pow(2,3)
8
>>> 2**3
8
>>> 2*2*2
8
>>> dir(math)
>>> dir(__buildins__)