In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "what is the method of Python function call". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
1. Function call # 1. To call a function, you need to know the name and parameter # 2 of the function. The number and type of parameters passed in by the calling function need to be the same as those defined by the function. For example, the absolute value of calling abs function print ("- 2) is:", abs (- 2) print ("100 absolute value is:", abs (100)) # 3. A function name is a reference to a function object, and you can assign a function name to a variable, which is equivalent to aliasing the function abs1 = abs # variable abs1 pointing to the abs function print (the absolute value of "- 1 is:", abs1 (- 1))
# result output:
The absolute value of-2 is: 2
The absolute value of 100 is: 100
The absolute value of-1 is: 1
two。 Function definition # defines a function using def# syntax: "def function name (parameter 1, parameter 2 return...): function body return returns value" def compareAB (AMaginb): if a > b: print ("a value is greater than b value!") Elif a = b: print ("an equals b!") Else: print ("an is less than b!") # call function compareAB (5) # result output: # a value is greater than b value! # empty function: can be used as a placeholder def nop (): pass# parameter check: Python interpreter can help us check whether the number of parameters is correct, but cannot check whether the parameter type is correct. # data type check instance def myAbs (x): if not isinstance (x, (int,float)): raise TypeError ("Bad Operand Type.") If x > = 0: return x else: return-x # input "a" will throw error myAbs ("A") # result output: -TypeError Traceback (most recent call last) in 15 16 # input "a" will throw an error-> 17 myAbs ("A") in myAbs (x) 7 def myAbs (x): 8 if not isinstance (x) (int,float):-> 9 raise TypeError ("Bad Operand Type.") 10 if x > = 0: 11 return xTypeError: Bad Operand Type.# returns multiple values import mathdef move (x step * math.cos (angle) angle = 0): nx = x + step * math.cos (angle) ny = y-step * math.sin (angle) return nx,ny# to get the return value x = move Math.pi / 6) print ("the value of x is% f, the value of\ ny is% f"% (xPowery)) # result output: # x the value of 151.961524 # y is 70.00000 years instance 1: converted from Euler angle to corresponding quaternion # value of quaternion calculated from angle import math# yaw: angle of rotation around z axis # pitch: the angle of rotation about the y axis; # roll: the angle of rotation about the x axis Def eulerToQuaternion (yaw,pitch Roll): W = math.cos (roll/2.0) * math.cos (pitch/2.0) * math.cos (yaw/2.0) + math.sin (roll/2.0) * math.sin (pitch/2.0) * math.sin (yaw/2.0) x = math.sin (roll/2.0) * math.cos (pitch/2.0) * math.cos (yaw/2.0)-math.cos (roll/2.0) * math .sin (pitch/2.0) * math.sin (yaw/2.0) y = math.cos (roll/2.0) * math.sin (pitch/2.0) * math.cos (yaw/2.0) + math.sin (roll/2.0) * math.cos (pitch/2.0) * math.sin (yaw/2.0) z = math.cos (roll/2.0) * math.cos (pitch/2.0) * math.sin (yaw/ 2)-math.sin (roll/2.0) * math.sin (pitch/2.0) * math.cos (yaw/2.0) return x The quaternion of 90 degrees around the z axis print ("quaternions of 90 degrees around the z axis is:", (eulerToQuaternion (math.pi/2,0,0) # print of 90 degrees around the y axis ("quaternions of 90 degrees around the y axis is:", (eulerToQuaternion (0memmath.pipe2)) # print of 90 degrees around the x axis ("quaternions of 90 degrees around the x axis is:", (eulerToQuaternion (0mem0math.pipace 2)
# result output:
The quaternion of 90 degrees around the z axis is: (0.0,0.0,0.7071067811865476, 0.7071067811865476)
The quaternion of 90 degrees around the y axis is: (0.0,0.7071067811865476, 0.0,0.7071067811865476)
The quaternion of 90 degrees around the x-axis is: (0.70710678118654776, 0.0,0.0,0.7071067811865476)
This is the end of the content of "what is the method of Python function call". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.