Picture

Python笔记 第一个Hello world

Python

Hello

print('Hello world')

变量

Python中变量不需要显示声明类型

words = 'Hello world'
print(words)

常见类型

# 数值
cash = 0

# 小数
card = 0.01

# 字符串
words = 'Hello str'

# 列表
lst = [1, 2, 3]

# 元组
tup = (1, 2, 3)

# 字典
dst = {'name': 'tom', 'age': 25, 'height': 175}

# 集合
col = set([1, 2, 3])

# 不可变集合
col2 = frozenset([1, 2, 3])

函数

def func(words):
    print(words)

words = 'Hello world'
func(words)

class Cat(object):

    def say(self):
        print('Cat say miao miao miao')

cat = Cat()
cat.say()