class Student:
def __init__(self, name, age):
self.name=name
self.age=age
def say_hello(self):
print(self.name, "say hello")
And, to run it, type the following in the same program:
alice=Student("Alice", 16)
alice.say_hello()
Do not forget the parenthesis.
Save the program as python1.py
And on linux run:
python python1.py
And you will see on the screen:
('Alice', 'say hello')
Here is another example:
class Base1:
def __init__(self,x,y):
self.x=x
self.y=y
def add1(self):
z=self.x+self.y
print(z)
def main():
foo=Base1(1,2)
foo.add1()
if __name__=="__main__":
main()
And you will see 3 was printed on screen.
To run an R program on linux, write an R program and save as rprog1.R
a=c(1,2,3)
for ( i in 1:3)
{ print(i)}
And run Rscript rprog1.R on linux, you will see:
[1] 1
[2] 2
[3] 3
No comments:
Post a Comment