2020-09-15_python

#!/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()
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值