目录
一、print函数
举例:
print a
print('这是一个%s'%(a))
二、变量类型
参考网站为:Python3 基本数据类型 | 菜鸟教程 (runoob.com)
Python3 中有六个标准的数据类型:
- Number(数字)
- String(字符串)
- List(列表)
- Tuple(元组)
- Set(集合)
- Dictionary(字典)
Python3 的六个标准数据类型中:
- 不可变数据(3 个):Number(数字)、String(字符串)、Tuple(元组);
- 可变数据(3 个):List(列表)、Dictionary(字典)、Set(集合)。
1.数字
a, b, c, d = 20, 5.5, True, 4+3j
2.字符串
str = 'Runoob'
3. 列表
list = [ 'abcd', 786 , 2.23, 'runoob', 70.2 ]
4. 元组
tuple = ( 'abcd', 786 , 2.23, 'runoob', 70.2 )
5. 集合
sites = {'Google', 'Taobao', 'Runoob', 'Facebook', 'Zhihu', 'Baidu'}
6. 字典
数据为键值对
tinydict = {'name': 'runoob','code':1, 'site': 'www.runoob.com'}
三、循环
参考:Python3 循环语句 | 菜鸟教程 (runoob.com)
1. while循环
count = 0
while count < 5:
print (count, " 小于 5")
count = count + 1
else:
print (count, " 大于或等于 5")
2. for循环
Python for 循环可以遍历任何可迭代对象,如一个列表或者一个字符串。
languages = ["C", "C++", "Perl", "Python"]
for x in languages:
print (x)
for i in range(5,9) :
print(i)
四、函数
参考:Python3 函数 | 菜鸟教程 (runoob.com)
def area(width, height):
return width * height
五、类
Python3 面向对象 | 菜鸟教程 (runoob.com)
1. 创建类
class Dog():
"""模拟小狗"""
def_init_(self,name,age):
"""初始化"""
self.name=name
self.age=age
def sit(self):
"""蹲下"""
print(self.name.title()+"蹲下了")
def roll_over(self):
"""打滚"""
print("^")
2. 实例化
Python3 面向对象 | 菜鸟教程 (runoob.com)
my_dog=Dog("while",6)
3.继承
略