#This is a Python comment.
print("Hello World!")
print("Hens", 25 + 30 / 6)
print("Let's talk about %s." % "Python")
print("The first digit is %d." % 0)
print("PI = %r." % 3.142) #%r is the formatter for the debugger
print("I play %s and %s." % ("soccer", "basketball"))
print("Beginning", end="") #end="" no space, or new line
print("Ending")
print("." * 10) #Print ten .
formatter = "%r %r %r %r"
print(formatter % (1, 2, 3, 4))
months = "Jan\nFeb\nMar\nApr\nMay\nJun\nJul\nAug"
print(months)
print("""
There's something going on here.
With the three double-quotes.
We'll be able to type as much as we like.
Even 4 lines if we want, or 5, or 6.
""")
cars = 100 #Declare and initialize variable.
print("How tall are you?", end="")
height = input()
weight = input("How much do you weigh? ")
print("Height %r weight %r", % (height, weight))
Command-line.
REM Translate Python 2 file to Python 3
Python E:\Python33\Tools\Scripts\2to3.py filename.py
#Python Exercise13ParametersUnpackingVariables.py 1 2 3
script, first, second, third = sys.argv
filename = input("Enter the name of the file to open")
fileHandle = open(filename)
fileContent = fileHandle.read()
print(fileContent)
fileHandle.close()
target = open('sample.txt', 'w')
target.truncate()
target.write("This is the beginning of the file.\n")
target.close()
lengthOfGood = len("Good")
print(lengthOfGood)
Reference
Leave a comment