#!/usr/local/bin/python
# -*- coding: utf-8 -*-
import math
import string
# def product(*numbers):
# result = 1
# for number in numbers:
# result*=number
# return result
#
# ret = product(1,2,3,4)
# print("1*2*3*4="+str(ret)) # 将数字转换为字符串
#幂运算
# def sum_of_power(*numbers,power=1):
# sum = 0
# for number in numbers:
# sum += number ** power
# return sum
#
# ret2 = sum_of_power(1,2,3,4,5,power = 2)
# print("幂运算结果为"+ str(ret2))
# *后面不允许出现位置参数,但关键字是允许的
# def heron2(a,b,c,*,units = "meters"):
# s = (a+b+c)/2
# area = math.sqrt(s*(s-a)*(s-b)*(s-c))
# return "{0}{1}".format(area, units)
#
# ret3 = heron2(3,4,5)
# ret4 = heron2(3,4,5,units = "inches")
# print(ret3,ret4)
# **映射拆分操作符 (字典)
# def add_person_details(ssn,surname,**keywords):
# print("SSN=",ssn)
# print(" surname=",surname)
# for key in sorted(keywords):
# print(" {0} = {1}".format(key, keywords[key]))
#
# print(add_person_details(585245895, "Luther",forname="Leixi",age = "46"))
def print_args(*args,**keywords):
for i,arg in enumerate(args): #enumerate() 函数用于将一个可遍历的数据对象(如列表、元组或字符串)组合为一个索引序列,同时列出数据和数据下标,一般用在 for 循环当中
print("positional argument {0} = {1}".format(i, arg))
for key in keywords:
print("keywords argument {0} = {1}".format(key,keywords[key]))
# -*- coding: utf-8 -*-
import math
import string
# def product(*numbers):
# result = 1
# for number in numbers:
# result*=number
# return result
#
# ret = product(1,2,3,4)
# print("1*2*3*4="+str(ret)) # 将数字转换为字符串
#幂运算
# def sum_of_power(*numbers,power=1):
# sum = 0
# for number in numbers:
# sum += number ** power
# return sum
#
# ret2 = sum_of_power(1,2,3,4,5,power = 2)
# print("幂运算结果为"+ str(ret2))
# *后面不允许出现位置参数,但关键字是允许的
# def heron2(a,b,c,*,units = "meters"):
# s = (a+b+c)/2
# area = math.sqrt(s*(s-a)*(s-b)*(s-c))
# return "{0}{1}".format(area, units)
#
# ret3 = heron2(3,4,5)
# ret4 = heron2(3,4,5,units = "inches")
# print(ret3,ret4)
# **映射拆分操作符 (字典)
# def add_person_details(ssn,surname,**keywords):
# print("SSN=",ssn)
# print(" surname=",surname)
# for key in sorted(keywords):
# print(" {0} = {1}".format(key, keywords[key]))
#
# print(add_person_details(585245895, "Luther",forname="Leixi",age = "46"))
def print_args(*args,**keywords):
for i,arg in enumerate(args): #enumerate() 函数用于将一个可遍历的数据对象(如列表、元组或字符串)组合为一个索引序列,同时列出数据和数据下标,一般用在 for 循环当中
print("positional argument {0} = {1}".format(i, arg))
for key in keywords:
print("keywords argument {0} = {1}".format(key,keywords[key]))
print(print_args(1234325,33335,"LIJDF","DASJG",test1 = "zhangsan",test2 = "adf"))
备注:
int(x [,base ]) 将x转换为一个整数
long(x [,base ]) 将x转换为一个长整数
float(x ) 将x转换到一个浮点数
complex(real [,imag ]) 创建一个复数
str(x ) 将对象 x 转换为字符串
repr(x ) 将对象 x 转换为表达式字符串
eval(str ) 用来计算在字符串中的有效
Python表达式,并返回一个对象
tuple(s ) 将序列 s 转换为一个元组
list(s ) 将序列 s 转换为一个列表
chr(x ) 将一个整数转换为一个字符
unichr(x ) 将一个整数转换为Unicode字符
ord(x ) 将一个字符转换为它的整数值
hex(x ) 将一个整数转换为一个十六进制字符串
oct(x ) 将一个整数转换为一个八进制字符串