Python Tutorial
#!/usr/bin/python # prints the string print "First Python Code!";Output:
$comment1.py First Python Code!here single line comment 'prints the string' is ignored by python interpreter in python scripts file.
#!/usr/bin/python
'''
print "Hello All!"
print "Welcome to python"
'''
input_str = raw_input("Please enter a string:")
print("Entered string is %s" % input_str)
Output:
$ python first.py Please enter a string:hi Entered string is hitwo print lines are ignored by python interpreter.
#!/usr/bin/python
#!/usr/bin/python
"""
print "Hello All!"
print "Welcome to python"
"""
input_str = raw_input("Please enter a string:")
print("Entered string is %s" % input_str)
Output:
$ python first.py Please enter a string:hi Entered string is hiWe cannot use 3 single quotes in starting and 3 double quotes in end of the lines or vise versa.
#!/usr/bin/python
'''
print "Hello All!"
print "Welcome to python"
"""
input_str = raw_input("Please enter a string:")
print("Entered string is %s" % input_str)
Python interpreter error:
$ python first.py
File "first.py", line 11
^
SyntaxError: EOF while scanning triple-quoted string literal
#!/usr/bin/python
def sum(a, b):
"""Sum method
Calculates sum value of variable a and b,
returns sum value.
"""
return a+b
result = sum(4,6)
print sum.__doc__
print("sum of 4 and 6 is %d" % result)
Output:
$ python docstrings.py
Sum method
Calculates sum value of variable a and b,
returns sum value.
sum of 4 and 6 is 10
Python Tutorial
Privacy Policy | Copyright
2020 - All Rights Reserved. | Contact us
| Report website issues in Github
| Facebook page
| Google+ page