Is there a way to make a custom print function in Python with parentheses and quotes the same as the print functions?
example: out("hello world"), output: hello world
another example: out("hello there") then the output would be hello there.
Is there a way to do that, so out would mean print in just another word?
CodePudding user response:
I'm not sure if this is what you mean, but this could be what you are looking for:
def out(msg):
print(msg)
After this definition, typing out("Hello world")
will have the exact same effect as typing print("Hello world")
. It won't work, however, for more than one argument, e.g. output of print("Hello", "world")
would be Hello world
, whereas out("Hello", "world")
would fail.
CodePudding user response:
you question is not clear. If you can edit your post including your script and your output would help us answering much better. With your current question, as far as I understand you want to achiev, you need function that would print what where your input and print the string;
For that you need to define a simple function and it will be using python print function to print your text;
def out(input_text):
print(f"{input_text}")
out("Hello World")
Result
Hello World
If you want your out function to accept multiple text inputs you can try below;
def out(*args):
output = ""
for arg in args:
output = " "
output = arg
print(output)
out("Hello", "This")
Result;
Hello This