1

How to write this (Java) in Python?

class Test
{
  private String test1 = "test";
  private static void main(String args[])
  {
    System.out.println("test" + test1);
  }
}
2
  • 5
    You can't have private stuff in python. The closest you can get to it is name mangling Commented Nov 24, 2011 at 11:56
  • 2
    Actually your example won't even compile, since test1 is an instance variable and main is a static function. Commented Nov 24, 2011 at 12:16

2 Answers 2

5

Since Python supports code outside of classes, the equivalent is as simple as:

test1 = "test"
print("test" + test1)

UPDATE: To get the args:

import sys
print sys.argv

You really should start with the tutorial!

Sign up to request clarification or add additional context in comments.

2 Comments

But how do i get the args[] in your example? like in mine i can $ java -jar Test.jar "command line input"
Well you're example did not use args.
3

Hmmm, like this:

test1 = "test"
print "test" + test1

But if you are using Python 3 you must write print("test" + test1).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.