Python第一周学习
1.Python支持命令式编程,函数式编程,面向对象设计
2.python是一种动态类型语言,变量的类型可以随时变化
>>>x=3
>>>print(type(x))
<class 'int'>
>>>x='Hello World.'
>>>print(type(x))
<class 'str'>
>>>x=[1,2,3]
>>>print(type(x))
<class 'list'>
3.python中,允许多个变量指向同一个值,例如;
>>>x=3
>>>id(x)
>1786684560
>>>y=x
>>>id(y)
1786684560
4.输出函数print
print('Hello','World!') #Hello World!
print(3,2,8) #3 2 8
print(3,2,8, sep=',') #3,2,8
print(8,26,18,sep=':') #8:26:18``
Python输出str.format()
<模板字符串>format(<逗号分隔的参数>)
print(’{},{},{}’.format(‘Tom’,‘男’,40)
5.python输入:input()
input()函数:
print('Hello','World!')
s=input()
print("Hello",s)
print(input())
读入的字符串不能直接用于数学运算
s=input() 100
print(3*s) 100100100
a=input() 10
b=input() 50
print(a+b) 1050
6.python使用对象模型来存储数据,构造任何类型的值都是一个对象
7.range()语法格式为range(start,end,step)
>>>range(5)
range(0,5)
>>>list(range(5))
[0,1,2,3,4]
>>>liat(range(1,10,2))
[1,3,5,7,9]
>>>list(range(9,0,-2))
>[9,7,5,3,1]