Python: Printing and Commenting
Printing:
The print() function that prints the specified message to the screen, or other standard output text. The message can be a string, or any other object, the object will be converted into a string before written to the screen.
Input: print("To be or not to be", "is that the question?", sep="---")
Output: To be or not to be---Is that the question?
When it comes to printing something in the Maya script editor you would add a little bit of extra text before the print command so that the script editor recognises the command. To generate a Poly-Cube within Maya you would write the following within the script editor:
Input: import maya.cmds as cmds
cmds.polyCube()
Output: 1 Poly-Cube
You would use this exact same command to generate of 3D objects but instead of writing "PolyCube" you would put "PolySphere" and that would generate a 3D Sphere. Now the one thing that makes this piece of code work is "import maya.cmds as cmds" , this allows Maya to recognise the command within the Python Editor so that a piece of code would work as you intend it to. As such when using the Python editor with in Maya always use this piece of text before writing out the rest of your code so that it works and produces what you intend to.
Commenting:
Comments in Python are identified with a hash symbol, #, and extend to the end of the line. Hash characters in a string are not considered comments, however. There are three ways to write a comment - as a separate line, beside the corresponding statement of code, or as a multi-line comment block.
for example:
# print("Hello world")
print("Hello campers")
to produce a comment within python you would place a Hashtag "#" in front of whatever piece of coding you make/use. Comments you can also place them after the piece of code that you are going to execute within python.
this will become quite helpful for when designing large amounts of codes for 3D Animation or a generic coding that you will only need to test a small fraction of of work to see each parts of the finished work.
Programming for computer Animation and VFX TB1
Status | In development |
Category | Other |
Author | up2146107 |
More posts
- Python: Integers, Floating Point Numbers and Complex NumberDec 15, 2022
- Python : Functions and Argument and ReturnDec 15, 2022
- Python: Type() and factorials and VariablesDec 15, 2022
Leave a comment
Log in with itch.io to leave a comment.