#!/usr/bin/python3
#python_test
#函数
def area(a,b):
return a*b
print(area(3,6))
def change(a):
print(id(a)) # 指向的是同一个对象
a=10
print(id(a)) # 一个新对象
a=1
# print(id(a))
change(a)
# 加了星号 * 的参数会以元组(tuple)的形式导入,存放所有未命名的变量参数。
def greetPerson(*name):
print('Hello', name)
greetPerson('Runoob', 'Google')
#递归函数
#x=4在函数中先执行x+Foo(x-1),一直执行到x=1为止。最终结果4+3+2+1=10
def Foo(x):
if (x==1):
return 1
else:
return x+Foo(x-1)
print(Foo(7))
numbers = [1, 3, 6]
newNumbers = tuple(map(lambda x: x , numbers))
print(newNumbers)
x = True
country_counter = {}
def addone(country):
if country in country_counter:
country_counter[country] += 1
else:
country_counter[country] = 1
addone('China')
addone('Japan')
print(len(country_counter))
confusion = {}
confusion[1] = 1
confusion['1'] = 2
confusion[1] += 1
print(confusion[1] )
sum = 0
for k in confusion:
sum += confusion[k]
print(sum)
class MyClass:
"""一个简单的类实例"""
i = 12345
def f(self):
return 'hello world'
# 实例化类
x = MyClass()
# 访问类的属性和方法
print("MyClass 类的属性 i 为:", x.i)
print("MyClass 类的方法 f 输出为:", x.f())
class test11:
def f(self):
print(self.__class__)
a=test11()
a.f()